简体   繁体   中英

Java: Not specifying type in when instantiating objects

What is the practical difference between

Map<String, String> myMap = new HashMap<String, String>();

and

Map<String, String> myMap = new HashMap<>();

Neither throw any warnings and both seem to work fine ...

The second notation is called diamond operator , and was introducted in Java 7 as part of the project Coin ( JSR 334 ).

There is no pratical difference between the two notations, it just save our tired fingers from few keybord entries :)

A good article about this is available on javaworld

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM