
resources.report.rules.pmd.InstantiationToGetClass.html Maven / Gradle / Ivy
InstantiationToGetClass
InstantiationToGetClass
Avoid instantiating an object just to call getClass() on it; use the .class public member instead.
This rule is defined by the following XPath expression:
//PrimarySuffix
[@Image='getClass']
[parent::PrimaryExpression
[PrimaryPrefix/AllocationExpression]
[count(PrimarySuffix) = 2]
]
Example:
public class Foo {
// Replace this
Class c = new String().getClass();
// with this:
Class c = String.class;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy