Why again inline classes cannot inherit from super...
# language-proposals
a
Why again inline classes cannot inherit from super classes, what is the conflict?
a
@Aregev2 Because at runtime there is no class
inline class PositiveInteger(private val data: Int)
is just a regular
Int
at runtime
b
I see where Alon's coming from tho. There's no reason the compiler can't pretend there is a type hierarchy, even if the runtime can't. This would be useful especially with inheriting functionality
a
and that will get confusing especially for people new to kotlin:
Copy code
interface Foo

inline class Bar(private val s: String) : Foo

fun doFoo(foo: Foo)

val bar = Bar("Hello World")

doFoo(bar) //Doesn't work, although Bar "inherits" from Foo
b
Yes, that looks annoying and confusing
k
Isn't there still autoboxing for cases like this?
i
Inline classes can implement interfaces, but can't inherit from other classes. Because those classes can have state and inline class can only handle one piece of state — a property declared in its primary constructor.
k
That reminds me, I wanted to ask whether the "one single property" limitation can/will be lifted in the future? Is it even possible to return multiple values on the JVM?
a
hm, if only interfaces are allowed, my example would actually work with autoboxing
a
Its really disappointing that unsigned integers wont extend number, I mean Interfaces are kind of hierarchy as well no? (also, my OCD is crashing badly ;P)
b
@Aregev2 see my mini-proposal from the other day
a
So in case of
UInt
for example, will we be able to acess `Number`'s functions and fields? as in runtime it is translated it an
Int
k
Why does everyone seem to like the
Number
interface class 😐
a
It's an abstract class, and I don't know 🤷
k
Even worse, an abstract class that doesn't have any actual state.
a
Because it was the legacy (
Integer
) 🤷
b
I hate it, and prefer Swift’s setup. I still have qualms with theirs, but it’s much closer to my ideal and the qualms are minor
👍 1
a
So will we be able to access
Number
functions anyways?
As in runtime UInt is Int basically
k
And regardless, the conversions would be wrong anyway.
i
@Aregev2 You won't be able to cast
UInt
as
Number
. However there are conversion functions, like
.toInt()
or
.toLong()
, which return value that can be cast to
Number