Is null check needed before calling instanceof?

Technology CommunityCategory: JavaIs null check needed before calling instanceof?
VietMX Staff asked 3 years ago
Problem

Will

null instanceof SomeClass

return false or throw a NullPointerException?

No, a null check is not needed before using instanceof. The expression

x instanceof SomeClass // return false if x is null

is false if x is null.