== vs === in kotlin(polymorphism behaviour)

<p>one line answer is === will use in&nbsp;<strong>data classes</strong>&nbsp;in kotlin.<br /> * I will try to explain == vs === operator use cases in Kotlin with respect to polymorphism(&ldquo;Think like a compiler and act like a run-time environment&rdquo;)<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(&ldquo;Earth&rdquo;)<br /> val objRef1 = ClassA(&ldquo;Earth&rdquo;)<br /> println(objRef) // @35&hellip;.<br /> println(objRef1) // @36&hellip;.<br /> println(objRef == objRef1) // false &mdash; for normal class, true &mdash; for data class<br /> Unlike in Java we don&rsquo;t have .equals() api to&nbsp;<strong>check the object inside data</strong>&nbsp;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&rsquo;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>