Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make the acquisition of reflection object by java

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report