Will the Kotlin compiler optimize away / remove me...
# announcements
b
Will the Kotlin compiler optimize away / remove methods that were generated by declaring a class a
data class
, but ended up being unused?
đźš« 1
Do people think about this when deciding
data class
or
class
?
j
No. For one, in libraries, you can't know what APIs your consumers are going to use or whether they'll want to put your type into a map as a key.
👆 2
b
Makes sense. Thanks!
g
In jvm I don’t know if this exists and could be very interesting. Either way in kotlin-js we have something similar (kotlin-dce plugin, for dead code elimination), but I don’t really know what this do.
j
Every platform had some sort of tree shaking you can opt in to at the leafs
g
@jw, I don’t know. I don’t think we can’t eliminate unused code from libraries. Of course, if we are using reflection this could be a problem, but for your example, if you put a type in a map we can follow only that one that is being put and forget the other ones.
j
By leafs I mean leaf modules. You run DCE on JS apps. You run R8 or ProGuard for Java bytecode. You run LTO or whatever for native