Java 7 also introduces a change that means less typing for you when dealing with
generics. One of the problems with generics is that the definitions and setup of
instances can be really verbose. Let’s suppose that you have some users, whom you
identify by userid (which is an integer), and each user has one or more lookup tables
specific to that user. What would that look like in code?
Map<integer, string="">> usersLists = new HashMap<integer, string="">>();</integer,></integer,>
Map> usersLists = new HashMap<>();
The “diamond syntax” name
This form is called “diamond syntax” because, well, the shortened type information
looks like a diamond. The proper name in the proposal is “Improved Type Inference
for Generic Instance Creation,” which is a real mouthful and has ITIGIC as an acronym, which sounds stupid, so diamond syntax it is.
讀書筆記:The Well-Grounded Java Develope