Quantcast
Channel: User Chase Seibert - Stack Overflow
Viewing all articles
Browse latest Browse all 43

Answer by Chase Seibert for How are anonymous inner classes used in Java?

$
0
0

I use them sometimes as a syntax hack for Map instantiation:

Map map = new HashMap() {{   put("key", "value");}};

vs

Map map = new HashMap();map.put("key", "value");

It saves some redundancy when doing a lot of put statements. However, I have also run into problems doing this when the outer class needs to be serialized via remoting.


Viewing all articles
Browse latest Browse all 43

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>