On Mon, 17 Mar 2025 01:58:55 GMT, Luca Kellermann <d...@openjdk.org> wrote:
> > I see that, probably due to prior `java.util` contracts, a stable list or > > map cannot present a `toString` with unset component values. A stable list > > or map uses a “canned” `toString` method that calls `get`, which must force > > all component values to be evaluated before the `toString` can be printed. > > I also noticed this issue of `toString` eagerly setting all elements of > stable collections and agree that it probably shouldn't do this. Note that > all views of these collections (obtained via `List.subList`, `List.reversed`, > `Map.entrySet`, `Map.values`, etc.) would also need their own `toString` > implementation. > > > Just as `WeakHashMap` bends the `Map` API (regarding `equals`), I think > > `StableValue` composites should bend the `List` and `Map` APIs, regarding > > `toString`. Sometimes the contracts have to be bent for the whole design > > to fit together. > > Neither `List`, `Set`, nor `Map` mention any requirements for `toString` in > their interface specification. Only `AbstractCollection` and `AbstractMap` > have a default implementation of `toString`. So I don't think any contract > would be bent here. I think requiring the `toString()` method of `StableList::subList` and `StableList::reversed` is a bit too much, at least in the first incarnation. However, I have noted this as a candidate in future implementations. ------------- PR Comment: https://git.openjdk.org/jdk/pull/23972#issuecomment-2765490546