3 ms·
Mark, I am sure you know this, but I am posting this for the benefit of others who might not. For literal maps, I tend to use double brace initialization style
by mavelikara 11y ago
Mark, I am sure you know this, but I am posting this for the benefit of others who might not.
For literal maps, I tend to use double brace initialization style. It is more verbose than languages with direct literal support for maps and creates an extra anonymous class, but it keeps the map in a single syntactic construct. For lists, I use Arrays.asList(a,b,c) style; if you static import the method it reads nicely as-list-a-b-c.
- pjmlp 11y agoWhich is a no-go in Android as it can prevent GC in some cases, because as anonymous inner class it holds a reference to its parent and you end up leaking Activities. It is usually presented as anti-pattern in talks about Android performance.
- mavelikara 11y agoAh, I have never programed for Android devices. Thanks for pointing this out.