https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
a

Aregev2

07/21/2018, 8:12 PM
Why again inline classes cannot inherit from super classes, what is the conflict?
a

Andreas Sinz

07/21/2018, 8:41 PM
@Aregev2 Because at runtime there is no class
inline class PositiveInteger(private val data: Int)
is just a regular
Int
at runtime
b

benleggiero

07/21/2018, 8:49 PM
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

Andreas Sinz

07/21/2018, 9:30 PM
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

benleggiero

07/21/2018, 11:16 PM
Yes, that looks annoying and confusing
k

karelpeeters

07/21/2018, 11:20 PM
Isn't there still autoboxing for cases like this?
i

ilya.gorbunov

07/22/2018, 11:30 AM
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

karelpeeters

07/22/2018, 11:39 AM
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

Andreas Sinz

07/22/2018, 12:10 PM
hm, if only interfaces are allowed, my example would actually work with autoboxing
a

Aregev2

07/22/2018, 3:00 PM
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

benleggiero

07/22/2018, 3:19 PM
@Aregev2 see my mini-proposal from the other day
a

Aregev2

07/22/2018, 4:33 PM
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

karelpeeters

07/22/2018, 4:34 PM
Why does everyone seem to like the
Number
interface class 😐
a

Aregev2

07/22/2018, 4:34 PM
It's an abstract class, and I don't know 🤷
k

karelpeeters

07/22/2018, 4:35 PM
Even worse, an abstract class that doesn't have any actual state.
a

Aregev2

07/22/2018, 4:36 PM
Because it was the legacy (
Integer
) 🤷
b

benleggiero

07/22/2018, 5:58 PM
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

Aregev2

07/24/2018, 9:05 PM
So will we be able to access
Number
functions anyways?
As in runtime UInt is Int basically
k

karelpeeters

07/24/2018, 9:07 PM
And regardless, the conversions would be wrong anyway.
i

ilya.gorbunov

07/24/2018, 9:34 PM
@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
7 Views