On Tue, 21 Mar 2023 13:53:27 GMT, Chen Liang <li...@openjdk.org> wrote:
>> It is possible but this keeps the mapper more local and only accessible >> where it is supposed to be used. For testing purposed, it might be better to >> have the class as you propose. > > If we want it local, I suppose we can convert the whole `ZoneOffsetMapper` > local with this singleton in `ofTotalSeconds` static method as well. What I mean is: final class LazyZoneOffsetMapper implements IntFunction<ZoneOffset> { private static final LazyZoneOffsetMapper INSTANCE = new LazyZoneOffsetMapper(); @Override public ZoneOffset apply(int slot) { int totalSeconds = slotToSeconds(slot); ZoneOffset newValue = new ZoneOffset(totalSeconds); ZoneOffset existing = ID_CACHE.putIfAbsent(newValue.getId(), newValue); return existing == null ? newValue : existing; } } we can inline this local class so we don't declare two classes nested `ZoneOffsetMapper` and local `Holder` for one purpose. This local class is still lazily loaded only if the `INSTANCE` field is used. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/12346#discussion_r1171302695