TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - Java Coding Standard
Search

Rule:  Optimization11Checked automatically with code checker

Synopsis:Avoid double brace initialization
Language:Java
Severity Level:5
Category:Optimization


Description:
Double brace initialization is a pattern to initialize objects, such as collections, concisely. However, it implicitly generates a new .class file, and the object holds a strong reference to the enclosing object. For those reasons, it is preferable to initialize the object normally, even though it’s verbose.
Set<String> countries = new HashSet<String>() { // violation
    {
       add("India");
       add("USSR");
       add("USA");
    }
};