On 5 May 2016 at 02:30, Stuart Marks <stuart.ma...@oracle.com> wrote:
>> I disagree with altering the iteration order. Guava's ImmutableSet and
>> ImmutableMap have reliable iteration specified to match creation
>> order. This aspect of the design is very useful.
>
>
> I think this is a reasonable thing to want, but it would be a different API.
> The current Set.of() and Map.of() APIs have unspecified iteration order, and
> I want to "enforce" that via randomizing the iteration order. Having
> unspecified iteration order, but with the implementation giving a stable
> order, is the worst of both worlds. It lets clients bake in inadvertent
> order dependencies, and then when we do change it, it breaks them. (This
> seems to happen every couple years with HashMap.) Randomizing iteration
> order helps preserve implementation freedom.
>
> That said, it's a fine thing to have a different API that gives a Set or Map
> with a stable iteration order. Several people have asked for this. I've
> filed JDK-8156070 to track this.

To be clear, I believe that the spec of Set.of() and Map.of() should
require iteration order matching insertion order (because the order is
very clearly defined in this case and anything else will be
surprising).

Stephen

Reply via email to