Java

Java

Made by DeepSource

Object.getClass does not need to be invoked on an instantiated object JAVA-W0077

Anti-pattern
Minor
Autofix

This method allocates an object just to call getClass() on it, in order to retrieve the Class object for it. It is simpler to just access the static .class property of the class itself.

Bad Practice

Class<SomeClass> c = new SomeClass().getClass();

Recommended

Class<SomeClass> c = SomeClass.class;

Just use the static .class property when you can statically determine the class object you need.

References