On Thu, 13 May 2021 20:52:33 GMT, Stephen Colebourne <scolebou...@openjdk.org> 
wrote:

> 8266846: Add java.time.InstantSource

src/java.base/share/classes/java/time/InstantSource.java line 68:

> 66:  * @implSpec
> 67:  * This interface must be implemented with care to ensure other classes 
> operate correctly.
> 68:  * All implementations that can be instantiated must be final, immutable 
> and thread-safe.

(I'm not an openjdk reviewer)

I'm wondering if we can revisit this "immutable" requirement as it is being 
shuffled from `Clock` to `InstantSource`.

This precludes an implementation that might be useful for testing, where the 
time provided by a single `InstantSource` instance can be adjusted manually in 
the test code.  To me that is a notable downside (worth breaking the contract 
for), and it's not so clear what the upside is.  "Immutable" seems like an odd 
way to describe the system clock anyway.

Do you know if the people who already use their own `InstantSource` / 
`TimeSource` / `Supplier<Instant>` have a mutable version that they use in 
tests?  I would be surprised if they're all satisfied with 
`InstantSource.fixed`, but perhaps my intuition is wrong here.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4016

Reply via email to