This is probably a stupid question but why does IntelliJ generate Java-dependent code in the commonMain part of a multi-platform project?
You can find an example in the thread.
Michael Paus
01/25/2022, 3:29 PM
Copy code
class EqualsGenerationTest {
val x: Double = 0.0
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as EqualsGenerationTest
if (x != other.x) return false
return true
}
override fun hashCode(): Int {
return x.hashCode()
}
}
mind blown 1
Michael Paus
01/25/2022, 3:31 PM
This is a simple test class with just one Double value in it. I generated the equals and hash code via IntelliJ. So I have two questions.
Why is it using
javaClass
and why does it compile?
I’d rather expect a line like this:
Copy code
if (other == null || this::class != other::class) return false
e
ephemient
01/25/2022, 6:49 PM
iirc kclass doesn't work for the synthetic classes generated at runtime for indy lambdas, not sure if that breaks this or not though
m
Michael Paus
01/26/2022, 7:32 PM
Well, in the end the
javaClass
did not compile (as expected). It was just the IntelliJ editor which did not complain about it. Nevertheless I still think this code should have never been generated this way or am I misunderstanding something?