How to make the acquisition of reflection object by java
Editor to share with you how to make java reflection object acquisition, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
How to get java.lang.Class object
Cash disk system production Q
SuppressWarnings ("all") / / suppresses warnings
Public class Deam {
Public static void main (String [] args) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Try {
/ / after a class is loaded, jvm will create a Class object of the corresponding class, and the whole information of the class will be put into the corresponding Class object
Class c=Class.forName ("cn.sxt.in.Demo")
System.out.println (c)
/ / Class name .class gets the Class object
Class strc=String.class
/ / object .getClass () gets the Class object
String path= "a"
Class strc2=path.getClass (); / / is the same as the Class object of String above
System.out.println (strc==strc2); / / true
Class intc=int.class; / / get the Class object of int
Int [] a=new int [10]
Int [] a2=new int [20]; / / the Class objects of the array are all the same
String [] a3=new String [10]; / / different types of arrays and arrays of different dimensions get different Class objects
System.out.println (a.getClass () .hashCode ())
System.out.println (a3.getClass () .hashCode ())
} catch (ClassNotFoundException e) {
E.printStackTrace ()
}
}
}
The above is all the content of the article "how to make reflection object acquisition by java". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!