https://kotlinlang.org logo
#announcements
Title
# announcements
r

ross_a

08/02/2019, 1:00 PM
Does anyone know why
kotlin.Number
is an abstract class, rather than an interface?
t

Tsvetozar Bonev

08/02/2019, 1:02 PM
Becuase it holds a value I reckon, would be kind of awkward to have an intreface backing data types.
e

elizarov

08/02/2019, 1:04 PM
No. It is purely abstract. Mostly, it is just a Java legacy in its design. But it is somewhat logical in the sense that being a number is pretty exclusive property. It is hard to imagine something being some other kind of entity and also serve its double-duty as a number.
(everything else about its design is quite illogical, though)
r

ross_a

08/02/2019, 1:04 PM
Yeah..
I'm looking at possibly porting this to use inline classes, but obviously inline classes can only implement interfaces, not extend abstract classes
at a first glance I think you can get the performance characteristics of what's called the "native decimal" in the benchmarks, but with the nicer API of the Immutable/MutableDecimal classes
It was just a curiosity I came across though, it doesn't have to extend Number, I just thought it was a bit strange. Thanks for the confirmation 🙂
k

karelpeeters

08/02/2019, 4:42 PM
Just don't extend it, the
Number
class is almost completely useless anyway.
2 Views