O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting a Class Object

MyClass a = new MyClass();
											a.getClass();

The most basic thing you usually do when doing reflective programming is to get a Class object. Once you have a Class object instance, you can obtain all sorts of information about the class and even manipulate the class. In this phrase, we use the getClass() method to get a Class object. This method of getting a Class object is often useful in situations in which you have the object instance but do not know what class it is an instance of.

There are several other ways of obtaining a Class object. If you have a class for which the type name is known at compile time, there is an even easier way of getting a class instance. You simply use the compiler keyword .class, as shown here: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required