Suspicious 'Class.getClass()' call
Reports getClass()
methods that are called on a java.lang.Class
instance.
This is usually a mistake as the result is always equivalent to Class.class
. If it's a mistake, then it's better to remove the getClass()
call and use the qualifier directly. If the behavior is intended, then it's better to write Class.class
explicitly to avoid confusion.
Example:
void test(Class<?> clazz) {
String name = clazz.getClass().getName();
}
After one of the possible quick-fixes is applied:
void test(Class<?> clazz) {
String name = clazz.getName();
}
New in 2018.2
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023