|
package copier |
|
|
|
import java.util.* |
|
|
|
class Copier { |
|
|
|
companion object { |
|
@JvmStatic |
|
fun main(args: Array<String>) { |
|
println("lets see default behaviour") |
|
val defA = Default("def", 1) |
|
val defB = Default("def", 1) |
|
val defC = Default("defC", 2) |
|
|
|
println("same ref defA and DEFb ${defA === defB}") |
|
println("equals ${defA == defB}") |
|
|
|
println("same ref defA and DEFc ${defA === defC}") |
|
println("equals ${defA == defC}") |
|
|
|
println("------------------------------------------------------------------------------") |
|
println("lets test model with good hashcode and good equals") |
|
|
|
|
|
val firstA = Model("first", 1) |
|
val firstB = Model("first", 1) |
|
val second = Model("second", 2) |
|
|
|
println("same ref firstA and firstB ${firstA === firstB}") |
|
println("equals ${firstA == firstB}") |
|
|
|
println("same ref firstA and second ${firstA === second}") |
|
println("equals ${firstA == second}") |
|
|
|
println("lets copy firstA") |
|
val copyA = firstA.copy() |
|
println("same ref firstA and copyA ${firstA === copyA}") |
|
println("equals ${firstA == copyA}") |
|
|
|
|
|
println("------------------------------------------------------------------------------") |
|
println("lets test model with random id") |
|
|
|
val randomA = ModelWithRndId("random", 1) |
|
val randomB = ModelWithRndId("random", 1) |
|
|
|
println("same ref randomA and randomB ${randomA === randomB}") |
|
println("equals ${randomA == randomB}") |
|
|
|
println("lets copy randomA") |
|
|
|
val copyRandom = randomA.copy() |
|
println("same ref randomA and copyRandom ${randomA === copyRandom}") |
|
println("equals ${randomA == copyRandom}") |
|
|
|
println("------------------------------------------------------------------------------") |
|
println("lets test bad equals") |
|
val badA = ModelWithBadEquals("badA") |
|
val badB = ModelWithBadEquals("badA") |
|
|
|
println("same ref badA and badB ${badA === badB}") |
|
println("equals ${badA == badB}") |
|
|
|
println("lets copy badA") |
|
|
|
val copyBad = badA.copy() |
|
println("same ref badA and copyBad ${badA === copyBad}") |
|
println("equals ${badA == copyBad}") |
|
|
|
println("------------------------------------------------------------------------------") |
|
println("lets test default with instance inside") |
|
|
|
val now = Date().time |
|
val date = Date(now) |
|
val instanceA = DefaultWithInstance(date) |
|
val instanceB = DefaultWithInstance(date) |
|
val instanceC = DefaultWithInstance(Date(now)) |
|
|
|
println("same ref defA and defB ${instanceA === instanceB}") |
|
println("equals ${instanceA == instanceB}") |
|
|
|
println("same ref defA and defC ${instanceA === instanceC}") |
|
println("equals ${instanceA == instanceC}") |
|
|
|
println("------------------------------------------------------------------------------") |
|
println("lets test default with array") |
|
val arrayA = arrayOf("one", "two") |
|
val withArrayA = DefaultWithArray(arrayA) |
|
val arrayB = arrayOf("one", "two") |
|
val withArrayB = DefaultWithArray(arrayB) |
|
|
|
println("same ref defA and defB ${withArrayA === withArrayB}") |
|
println("equals ${withArrayA == withArrayB}") |
|
|
|
println("------------------------------------------------------------------------------") |
|
println("lets test default with array but with overriden hashcode") |
|
|
|
val overridenArrayA = DefaultWithArrayOverriden(arrayA) |
|
val overridenArrayB = DefaultWithArrayOverriden(arrayB) |
|
|
|
println("same ref defA and defB ${overridenArrayA === overridenArrayB}") |
|
println("equals ${overridenArrayA == overridenArrayB}") |
|
|
|
println("------------------------------------------------------------------------------") |
|
println("lets test default list no overrides") |
|
|
|
val seedA = listOf("one", "two") |
|
val seedB = listOf("one", "two") |
|
val listA = DefaultWithList(seedA) |
|
val listB = DefaultWithList(seedA) |
|
val listC = DefaultWithList(seedB) |
|
println("same ref listA and listB ${listA === listB}") |
|
println("equals ${listA == listB}") |
|
println("same ref listA and listC ${listA === listC}") |
|
println("equals ${listA == listC}") |
|
|
|
|
|
} |
|
} |
|
} |
This is where the bug on the java compiler is mentioned
https://blog.jetbrains.com/kotlin/2015/09/feedback-request-limitations-on-data-classes/