Is there any active development on inline classes?...
# announcements
p
Is there any active development on inline classes? I find the idea so handy but the implementation is so limited. For example I like to use it for units:
inline class Calories(val value : Double)
But now I lose all functionallity of double. If I for example want to sum, substract or divide calories, I need to re-implement these basic math functions ontop of the
Calories
class as
operator fun plus
etc.
r
I believe that's kind of the point. If you just want
Calories
to be another name for
Double
, you use a typealias.
👍 5
k
If you find declaring each function to be tedious, you can always use a UOM library: https://github.com/kunalsheth/units-of-measure
p
Typealias doesnt provide type safety
Copy code
typealias Calories = Double
typealias Gram = Double

fun Calories.bmr() {

}

fun mistake(gram: Gram){
  gram.bmr()
}
r
Yes, that's exactly my point.
d
I wonder if
inline class Calories(val value: Double) : Double by value
would work...?
h
Compiler says no:
Inline class cannot implement an interface by delegation
r
Also,
Double
is not an interface
d
True 🙃, it was just the idea... but even that doesn't work..