https://kotlinlang.org logo
p

pdegand

04/06/2020, 8:25 AM
Hi, I’m gathering arguments to convince my team (java 11, Spring boot) to switch to Kotlin. In the codebase, we are using wrapper classes to specify primitives (eg:
class UserId { String userId; }
), this is a perfect usecase for Inline classes ! In the documentation, it’s noted that
primitive types are usually heavily optimized by the runtime, while their wrappers don't get any special treatment.
Do you have any concrete examples of the kind of optimizations you lose when using wrapper class instead of the primitive type (or the Inline class in KT) ?
d

David Eriksson

04/06/2020, 2:47 PM
Are you asking if your value objects (as I would call them) would be slower in Kotlin compared to Java?
p

pdegand

04/06/2020, 3:53 PM
no, according to the doc, I’m pretty sure they would be faster with KT inline classes, but i’m just curious of the kind of optimizations the runtime does when dealing directly with primitives instead of wrapper classes
2 Views