I want to print all the class names in a package and also to print the corresponding attributes and their data types in each package.
In one code, I am able to get the classnames in the form of string.
In another code I am able to get the attributes and their data types using Classname.class.getAttribute();
However I want to merge the two codes. Since in the first code I got the classnames in the form of string , I can't use Classname.class.getAttribute() since here Classname will be of type String.
So I want a method which will convert the "Classname" from String type to Class type.
I tried Class.forName() but it didn't work.
解决方案
Class> classType = Class.forName(className);
Make sure className is fully qualified class name like com.package.class Also, please share your error message that you see.