On Mon, 17 May 2021 14:13:06 GMT, Roger Riggs <rri...@openjdk.org> wrote:

>> 8266846: Add java.time.InstantSource
>
> src/java.base/share/classes/java/time/InstantSource.java line 165:
> 
>> 163:      */
>> 164:     static InstantSource fixed(Instant fixedInstant) {
>> 165:         return Clock.fixed(fixedInstant, ZoneOffset.UTC);
> 
> Instant might also implement InstantSource, returning itself.
> This fixed method would be unnecessary because an Instant is itself a 
> InstantSource.

While I can see the appeal, I don't think this would be a good choice. Doing so 
would add three methods to `Instant` that are of no value. `millis()` would 
duplicate `toEpochMilli()`, `withZone(zone)` would duplicate `atZone(zone)` and 
`instant()` would return `this`. Moreover it doesn't respect the rationale of 
the interface, which is explictly to return the current instant, not any random 
instant.

Effectively, this proposal is a variation of Scala's implicit conversions which 
were rejected during the development of JSR-310 as being more likely to cause 
bugs than help developers,

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

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

Reply via email to