Created
June 8, 2023 11:16
-
-
Save kalaiselvan369/464f0fb96c408566de90488032c480f1 to your computer and use it in GitHub Desktop.
JVM representation for primitive types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun main() { | |
| val a: Int = 100 | |
| val boxedA: Int? = a | |
| val anotherBoxedA: Int? = a | |
| // === means referential equality | |
| println(boxedA === anotherBoxedA) // true | |
| //JVM has predefined values for int between -128 to 127 hence above statement is true | |
| val b: Int = 10000 | |
| val boxedB: Int? = b | |
| val anotherBoxedB: Int? = b | |
| println(boxedB === anotherBoxedB) // false | |
| val c: Int = 10000 | |
| println(c == c) // Prints 'true' | |
| val boxedC: Int? = c | |
| val anotherBoxedC: Int? = c | |
| // data equality | |
| println(boxedC == anotherBoxedC) // Prints 'true' | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment