classname - How to extract the name of all classes in a normal String from java class? -
public class { public class b{ public class c { } } public class d { } }
if example how write java code names of classes a,b,c , d in string. highly appreciated. thank you
i came reflection based answer:
public static list<string> getclassnames(class baseclass) { list<string> classnames = new arraylist<string>(); classnames.add(baseclass.getsimplename()); (class subclass: baseclass.getclasses()) { classnames.addall(getclassnames(subclass)); } return classnames; }
which returned [a, d, b, c]. didn't make clear if order important.
Comments
Post a Comment