Java Reference
In-Depth Information
16.2. What's ahead for Java?
Let's look at some of these points, most of which are discussed in more detail on the JDK
Enhancement Proposal website at http://openjdk.java.net/jeps/0 . Here we take care to explain
why seemingly sensible ideas have subtle difficulties or interaction with existing features that
inhibit their direct incorporation into Java.
16.2.1. Collections
Java's development has been evolutionary rather than “big bang.” There have been many great
ideas added to Java, for example, arrays being replaced by collections and later augmented with
the power of streams. Occasionally a new feature is so obviously better (for example, collections
over arrays) that we fail to notice that some aspect of the supplanted feature hasn't been carried
across. One example is initializers for containers. For example, Java arrays can be declared and
initialized with syntax such as
Double [] a = {1.2, 3.4, 5.9};
which is a convenient abbreviation for
Double [] a = new Double[]{1.2, 3.4, 5.9};
Java collections (via the Collection interface) were introduced as a better and more uniform way
of dealing with sequences of data such as that represented by arrays. But their initialization has
been rather neglected. Think about how you'd initialize a HashMap. You'd have to write the
following:
Map<String, Integer> map = new HashMap<>();
map.put("raoul", 23);
map.put("mario", 40);
map.put("alan", 53);
What you'd like to be able to say is something like
Map<String, Integer> map = #{"Raoul" -> 23, "Mario" -> 40, "Alan" -> 53};
where #{...} is a collection literal —a list of the values that are to appear in the collection. This
seems uncontroversial as a feature, [ 1 ] but it's not yet part of Java.
1 The current Java proposal is described in http://openjdk.java.net/jeps/186 .
 
Search WWH ::




Custom Search