
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
49 lines
1.0 KiB
Plaintext
49 lines
1.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Because Double Brace Initialization (DBI) creates an anonymous class with a reference to the instance of the owning object, its use can lead to memory leaks if the anonymous inner class is returned and held by other objects. Even when there's no leak, DBI is so obscure that it's bound to confuse most maintainers.
|
|
|
|
|
|
For collections, use ``++Arrays.asList++`` instead, or explicitly add each item directly to the collection.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
Map source = new HashMap(){{ // Noncompliant
|
|
put("firstName", "John");
|
|
put("lastName", "Smith");
|
|
}};
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
Map source = new HashMap();
|
|
// ...
|
|
source.put("firstName", "John");
|
|
source.put("lastName", "Smith");
|
|
// ...
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Replace this syntax with a different type initialization.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
from \{\{ to \}\}
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|