JEP 186: Collection Literals

Tom Hawtin tom.hawtin at oracle.com
Fri Jan 31 13:07:05 PST 2014


On 31/01/2014 08:43, Remi Forax wrote:
> so an immutable class must be final.

Immutable classes needn't be final, just not subclassable. They're best 
left possibly non-final, with no public/protected constructors. (Kind of 
a shame "final" and "abstract" still appears in the output of javadoc.)

As a motivating example, take the mutable java.util.EnumSet. The type of 
element is fixed, so that can be used in deciding the object-lifetime 
implementation class. Non-public JumboEnumSet handles the general case, 
while RegularEnumSet the common case very efficiently.

For an immutable Lst, there may be say, a plain old ArrayLst and a 
SliceLst which returns a "sublist" of a Lst.

> If one day the JDK has persistent collections (and I hope it will),
> there will be not interface to abstract them.

Persistent collections could implement interfaces for use in 
Collections-type methods, although explicit use of adapters may be better.

Tom



More information about the lambda-dev mailing list