Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

すべてのクラスを取得する


public static void main(String args) {
List interfaces = getAllClasses(HashMap.class);

for (int i = 0; i < interfaces.size(); i++)
System.out.println(interfaces.get(i));
}

public static List getAllClasses(Class clazz) {
List classes = new ArrayList();
return getAllClasses(clazz, classes);
}

public static List getAllClasses(Class clazz, List classes) {
if(!classes.contains(clazz))
classes.add(clazz);

getAllInterfaces(clazz, classes);
Class c = clazz.getSuperclass();

if(c != null)
getAllClasses(c, classes);

return classes;
}

public static List getAllInterfaces(Class clazz, List classes) {
Class interfaces = clazz.getInterfaces();

for (int i = 0; i < interfaces.length; i++) {
if(!classes.contains(interfaces[i]))
classes.add(interfaces[i]);

getAllInterfaces(interfaces[i], classes);
}

return classes;
}