Java9 Features – Part 2 | Collections | JavaDocs | Example

More than 3 years after the release of Java 8, the next version, Java9, is now just around the corner with a tentative release date of September 21st, 2017.

I had described Java 9’s module system, Jshell , Interface enhancement in my previous posts, but there’s even more to this new version. Collections factory methods, improved Javadocs, Multi-release jars are often ignored under the shadows of Jshell and Jigsaw Module.



I. Collections factory methods
we often create a list/set and populate it with elements by calling add() several times. This is foolishness called redundancy.

List list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
		
Set<Integer> set=new HashSet<Integer>();
set.add(1);
set.add(2);
set.add(3);

Java9 brings factory method shown below:-

*******JAVA9*********
List<Integer> list = List.of(1,2,3);
Set<Integer> ints = Set.of(1, 2, 3);

List.of() and Set.of() is new factory methods which helps to instantiate collections.



II. Improved JavaDocs
I hope all of you like me turn to google for finding the right Javadoc page. Oracle finally realise that there is need for good docs. Below is the change :-

  • Search box is provided at right side of Javadoc where you can search any related class or interface.
  • New Javadoc page also includes information on which JDK module the class or interface comes from.



Previous Post :- Java 9 features – part 1 and interface in java7 vs java8 vs java9.

 
 


Leave a Reply

Your email address will not be published. Required fields are marked *