Main Tutorials

How to get a Java Class Object

As far as i know, there are 4 ways to get the Java Class object.

1. “.class”


Class cls = Address.class;

2. object.getClass()


Address address = new Address();
Class cls = address.getClass();

3. Class.forName()


Class cls = Class.forName("com.mkyong.io.Address");

4. ClassLoader.loadClass()


ClassLoader cl = ClassLoader.getSystemClassLoader();
Class  cls = cl.loadClass("com.mkyong.io.Address");

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments