Java 9 Example - Factory Methods for Collection - Creating Unmodifiable List, Set, and Map
Hello guys, this is my first article in Java 9 features on this blog and today you'll learn about my favorite feature "factory methods for collection" , which is introduced as part of JEP 269. The JEP stands for JDK enhancement proposal. If you have worked in Groovy or Kotlin then you know that how easy is to create the list with elements using collection literals e.g. to create a list of 1, 2, 3 you can simply write val items = listOf(1, 2, 3). Unfortunately, Java doesn't support that yet but things have been improved with the factory methods for collection in JDK 9 and it's almost like that. JDK has added static factory methods like of() on to basic Collection interfaces which you can use to create a list of items. Even though the Project Jigsaw or Java Module systems is the main highlight of Java 9 release, there are several other useful features which are more helpful from development point of view e.g. process API enchantment, Stream API enhancements and some...