I was running into problems with different teams at my employer using different Immutable Collection implementations and wanted to avoid writing code to adapt each Collection

Remi Forax forax at univ-mlv.fr
Sun Jan 31 21:19:49 UTC 2021


Hi Larry,
this design was considered and rejected when the collection API vas introduced in JDK 1.2
see https://mail.openjdk.java.net/pipermail/core-libs-dev/2020-May/066245.html

Furthermore, if List extends ImmutableList, it means that ArrayList implements ImmutableList which is just plain wrong.
Consider the following code
  record Foo(ImmutableList<String> list) { }
  var arrayList = new ArrayList<String>();
  var foo = new Foo(arrayList);
  System.out.println(foo.list()); // []
  arrayList.add("oops");
  System.out.println(foo.list()); // [oops]

regards,
Rémi

----- Mail original -----
> De: "Larry Diamond" <ldiamond at ldiamond.com>
> À: "jdk-dev" <jdk-dev at openjdk.java.net>
> Envoyé: Dimanche 31 Janvier 2021 21:28:33
> Objet: I was running into problems with different teams at my employer using different Immutable Collection
> implementations and wanted to avoid writing code to adapt each Collection

> I was thinking of submitting a proposal for UnmodifiableCollections for
> Java.
> 
> I wrote up a first draft of a JEP for this.
> 
> What do you think?
> 
> Thank you very much
> Larry Diamond


More information about the jdk-dev mailing list