You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That would be fine too. I am looking to use dependency injection to inject Clock instance into code and to be able to inject an instance that I can easily control.
What I am doing now is that I have:
class OverridableClock : Clock {
var instant: Instant? = null
override fun now() = instant ?: Clock.System.now()
operator fun plusAssign(duration: Duration) {
instant = now() + duration
}
}
I guess though since you you have a companion object I can go ahead and create such a function as an extension.
For what it's worth, requiring that Clock be a SAM would break proposals like #17 for very little benefit.
Given that #17 seems to now be going the way of not changing Clock interface and #382 proposes moving Clock to the standard library, i once again propose that Clock be made a a fun interface.
Agreed it is a ver small benefit, but it also has basically zero cost
Activity
ilya-g commentedon May 11, 2023
When an interface has a single abstract method, it doesn't automatically qualify to be a functional interface.
We can however consider providing a SAM-like constructor function for
Clock
, e.g.dalewking commentedon May 12, 2023
That would be fine too. I am looking to use dependency injection to inject Clock instance into code and to be able to inject an instance that I can easily control.
What I am doing now is that I have:
I guess though since you you have a companion object I can go ahead and create such a function as an extension.
kevincianfarini commentedon Dec 15, 2023
For what it's worth, requiring that
Clock
be a SAM would break proposals like #17 for very little benefit.dalewking commentedon May 8, 2024
Given that #17 seems to now be going the way of not changing Clock interface and #382 proposes moving Clock to the standard library, i once again propose that Clock be made a a fun interface.
Agreed it is a ver small benefit, but it also has basically zero cost