How do Kotlin Inline classes compare to other lang...
# announcements
b
How do Kotlin Inline classes compare to other languages' value types (e.g.
struct
in C#, Swift or even plain-old C)? I see there are a lot of similarities between the two concepts (let's say one is
struct
in Swift): they can implement interfaces/protocols, can have properties, methods, and both are allocated on the stack without any memory overhead (please correct me if I'm wrong). What are the differences other than Inline classes can only have one underlying primitive type?
d
At the moment, they can't have a non-public constructor.
Arrays of inline classes require boxing.
o
can only have one underlying primitive type
not necessary primitive
g
allocated on the stack
why on the stack? Isn't it heap most of the time?
k
Yes, normally objects are allocated on the heap. The point is that these structures don't do any heap allocation.
z
@ghedeon primitive types are on stack, objects are on heap... if I'm not wrong.
g
how awesome is that, right? 🙂 Just not related) Inner classes are not about primitive types.