Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 491 Bytes

UnnecessaryInstantiationToGetClass.md

File metadata and controls

21 lines (14 loc) · 491 Bytes

Pattern: Unnecessary instantiation to getClass()

Issue: -

Description

Avoid instantiating an object just to call getClass() on it; use the .class public member instead.

public class Foo {
 // Replace this
 Class c = new String().getClass();

 // with this:
 Class c = String.class;
}

Further Reading