Sunday, November 3, 2013

Till we move to Diamond Operator

Have you ever come across a scenario, where a single line of code may not be enough to declare a generalized collection? If you don’t remember, just refresh your memory with follow simple code example. It is pretty obvious, the redundant generalization cause the lengthy collection declaration. There is no wrong here but the language should do the RHS for us. Because the future of the code is depends on the cleanness of it.

How about follow code sample, which one is clearer to read or understand.

How we do it?
Before java 7, there is no automatic type inference feature or an operator bundled with java. In java 7 there is a way, it calls the diamond operator.

Functionality of Diamond operator. <>
Following code line has same effect as the above two map declarations.

Way for pre java 7 developers.
Generic static factory method is their survivor.

No comments:

Post a Comment