== vs === in kotlin(polymorphism behaviour)
<p>one line answer is === will use in <strong>data classes</strong> in kotlin.<br />
* I will try to explain == vs === operator use cases in Kotlin with respect to polymorphism(“Think like a compiler and act like a run-time environment”)<br />
* == shows different behaviour based on how we call, for example in<br />
normal class -<br />
the == checks the values inside the variable. So while creating an object we actual get the object reference value(hashcode value) not the orginal object. So when we want to compare two objects it returns false even the data is same becuase we are comparing the refernces instead of objects data.<br />
val objRef = ClassA(“Earth”)<br />
val objRef1 = ClassA(“Earth”)<br />
println(objRef) // @35….<br />
println(objRef1) // @36….<br />
println(objRef == objRef1) // false — for normal class, true — for data class<br />
Unlike in Java we don’t have .equals() api to <strong>check the object inside data</strong> becuase by-default kotlin class extends Any not Object class<br />
* So, in-order to achieve that functionality kotlin have data classes to compare the objects. Here, when we make our class to data class the == changes its behaviour(<strong>polymorphism</strong>) from comparing class instances values to class instances data inside the object.<br />
* Now, if we want to compare class instances values to checks both variables are pointing to same object in the heap or not,<br />
we can use === operator.<br />
* Now === this operator take the responsability of == in-order to comapre the object references in data classes.<br />
Note:<br />
If you don’t get the context of it or If I make any mistake while explaining feel free to reach out : )</p>
<p><a href="https://medium.com/@prasadperugu/vs-in-kotlin-polymorphism-behaviour-9902f9c394be">Click Here</a></p>