Back to Intellij Community

InstantiatingObjectToGetClassObject

java/java-impl/resources/inspectionDescriptions/InstantiatingObjectToGetClassObject.html

2025.3-rc-2261 B
Original Source

Reports code that instantiates a class to get its class object.

It is more performant to access the class object directly by name.

Example:

Class<?> c = new Sample().getClass();

After the quick-fix is applied:

Class<?> c = Sample.class;