https://kotlinlang.org logo
Title
u

user

06/27/2022, 5:51 PM
Can I get a syntax like Measure<DistanceUnit>.ZERO in Kotlin? I'm working in a larger codebase, there is a Distance class which had a companion object with a ZERO property, used as Distance.ZERO. I am now introducing a unit system: Distance will now be typealiased to Measure. So: On the one hand, unfortunately the companion object is shared between all Measures regardless of template parameter, so I wouldn't know what type to give ZERO. On the other hand, an extension property like val Distance.ZERO: Distance get() = Distance(0.0, DistanceUnit.METERS)...