forax at univ-mlv.fr
forax at univ-mlv.fr
Wed Apr 28 12:20:37 UTC 2021
----- Mail original -----
> De: "Stuart Marks" <stuart.marks at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Vendredi 23 Avril 2021 08:56:53
> Objet: Re: ReversibleCollection proposal
>> An API can not use ReversibleCollection as parameter before all the
>> implementations of Collection that have an ordering are updated to implement
>> ReversibleCollection instead of Collection.
>> By example, if I add a method
>> public void foo(ReversibleCollection c)
>> in my library, people that want to be able to use foo with an existing
>> collection with an ordering have to wait that collection implementation to be
>> So i will not add a method like foo in my API until enough (whatever enough
>> means) implementation of Collection with an ordering have migrated.
>> This is a similar issue as the migration from Python 2 to Python 3, it takes at
>> least 10 years, so in 10 years, I will be able to had a public method that
>> takes a ReversibleCollection in my API,
>> without people not be able to using it.
> This is a gigantic overstatement of the issue.
> It is true that an API *in the JDK* as a practical matter cannot change a
> parameter to ReversibleCollection, because it will break any callers that are
> currently passing Collection. The same is true of any library APIs where
> compatibility is a concern.
> However, it can be quite useful in many contexts to use ReversibleCollection as
> parameter. Newly introduced APIs can use ReversibleCollection. Certain APIs that
> consume List could reasonably be adjusted to consume a ReversibleCollection
> (More likely an overload would probably be added in order to preserve binary
You did not really answer to the real question, why should i use ReversibleCollection instead of a Collection as parameter.
You said that it's a better type because you can not send a HashSet, but as i said, sending a HashSet of 0 or 1 element is perfectly valid.
For me, we are not far from, it's typechecking for the sake of typechecking.
This can be an interesting exercise for my students but it is not really a goal in Java, we have Haskell and Scala for that.
I see the point of having getFirst()/getLast() or descendingSet() on LinkedHashMap (your right that getFirst() on Collection should be getAny()),
I don't see the point of using ReversibleCollection as a type of a parameter, there is no algorithm that uses a ReversibleCollection as parameter in the litterature.
More information about the core-libs-dev