February 1st, 2017

Java 9’s other new enhancements, Part 1

Java Language, others, Programing, by admin.

Barring further delays, Java 9 will reach general availability status on July 27. Its module system and Java Shell Read-Eval-Print Loop (REPL) tool are receiving considerable attention, but Java 9 also offers additional enhancements that will make this release memorable.

I’ve created a series of posts that explores some of these other new enhancements. This series attempts to answer at least some of your questions about these offerings. We’ll begin by focusing on the new convenience factory methods that have been added to various interfaces in the Java Collections Framework.

Convenience factory methods for collections

Java Enhancement Proposal (JEP) 269: Convenience Factory Methods for Collections defines several factory methods for conveniently creating instances of unmodifiable collections and maps with small numbers of elements. This section presents these methods after explaining why they’re necessary.

The need for convenience factory methods

Java is often criticized for its verbosity. For example, creating a small, unmodifiable collection (e.g., a list) involves constructing it, storing its reference in a local variable, invoking add() via the reference several times, and finally wrapping the collection to obtain an unmodifiable view. Consider the following example:

Back Top

Leave a Reply