I'm not understanding inline classes... What do th...
# announcements
t
I'm not understanding inline classes... What do they do? I only have a small amount of knowledge of the JVM and stack/heap stuff. etc. I am trying to improve my knowledge in that sector of things.
m
It’s for performance. It’s not a good idea to have small one-property objects in memory everywhere. Primitive types take up much less memory Inline classes give you the best of both worlds. It’s a normal object until it’s compiled, where it's replaced with the primitive property
s
And it's sort of a way of sub-typing. Eg an email and an address can be represented by a String. But they should never be assigned to each other. Inline classes help here. Create an inline class
Email
,with a String, and one called
Address
, with a String. Both are now kinda like sub-types of String, through their boxing and un-boxing. They are both like Strings, but one cannot assign one to the other.
👍 2