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

Larry Diamond ldiamond at ldiamond.com
Sun Jan 31 22:10:57 UTC 2021


Wow thanks for getting back to me so quickly.   I'll read over the existing
conversation.   Thank you very much

On Sun, Jan 31, 2021 at 4:19 PM Remi Forax <forax at univ-mlv.fr> wrote:

> 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