Or do I have to do that optimization manually?
# announcements
p
Or do I have to do that optimization manually?
i
As I recall Kotlin follows
Effective Java
equality guidelines, so
equals
the implementation it is already optimised. Under the hood object compression works more or less like this: 1. Check if object is the same (current vs object passed as argument) 2. Check hashCode (if equal go to step 3) 3. Check if values all hashCodes of properties declared in the primary constructor are equal
p
Ok, thanks for the info
c
For reference, see this gist: https://gist.github.com/cbruegg/9b50854343dae9fcdb7a057c14892608 It shows the Java-equivalent of the data class defined in
X.kt
. As you can see, the lists are not compared by identity first, but
equals
is callled directly after a null-check. However, most
List
implementations in the JDK actually extend
AbstractList
, which performs the reference identity check in its
equals
implementation: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/java/util/AbstractList.java#l512
👍 1