import java.util.*;
import java.lang.Class;
/**
* @author Ihavegotyou
* 打印类继存层次树型结构
*/
public class InheritRelation {
static Stack<Class> stack = new Stack<Class>();
static Class fClass;
static Class getClassInheritRelation(final Class aClass) {
if (aClass != null) {
Class parentClass = aClass.getSuperclass();
if (parentClass != null)
stack.push(parentClass);
return getClassInheritRelation(parentClass);
} else
return null;
}
public InheritRelation(final Class aClass) {
super();
fClass = aClass;
getClassInheritRelation(aClass);
printInheritRelation();
}
public InheritRelation() {
new InheritRelation(this.getClass());
}
static void printInheritRelation() {
int i = 0;
while (!stack.isEmpty()) {
for (int j = 0; j <= i; j++)
System.out.print('.');
System.out.println(stack.peek().toString().substring(6));
stack.pop();
i++;
}
for (int j = 0; j <= i; j++)
System.out.print('.');
System.out.println(fClass.toString().substring(6));
System.out.println();
}
public static void main(String[] args) {
InheritRelation stack = new InheritRelation(new Stack().getClass());
InheritRelation hashmap=new InheritRelation(new HashMap().getClass());
try {
Class.forName("InheritRelation").newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
}