"Diamond Syntax" is the project coin improvement in JAVA 7.
For example, Earlier we use to declare collections like this:
For example, Earlier we use to declare collections like this:
ArrayList<String> str=new ArrayList<String>();
Map<String,File> myfile=new
HashMap<String,File>();
Notice that the type parameters are duplicated in these declarations. As of Java 7 these declarations could be simplified to:
ArrayList<String> str=new ArrayList<>();
Map<String,File> myfile=new HashMap<>();
This <> is known as Diamond operator.
NOTE: You cannot swap these , the following is NOT legal.
Map<> myfile=new HashMap<String,File>(); // Not a legal Diamond Syntax
No comments:
Post a Comment