Instance Of (type checking)¶
The instanceof
keyword allows to verify if an Object variable is an instance of the provided type.
It cannot be used on primitive variables, and will always return false
on null
variables.
Examples¶
Integer a = 1
println(a instanceof Integer) // true
println(a instanceof Number) // true
println(a instanceof Long) // false
Not Instance Of¶
To check the opposite, use !instanceof
Integer a = 1
println(a !instanceof Integer) // false
println(a !instanceof Number) // false
println(a !instanceof Long) // true