Skip to content

Instantly share code, notes, and snippets.

@kalaiselvan369
Created June 8, 2023 11:16
Show Gist options
  • Select an option

  • Save kalaiselvan369/464f0fb96c408566de90488032c480f1 to your computer and use it in GitHub Desktop.

Select an option

Save kalaiselvan369/464f0fb96c408566de90488032c480f1 to your computer and use it in GitHub Desktop.
JVM representation for primitive types
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