Besides null also gets typecast into any user-defined objects inspite of instanceof returning false.. how is it possible???Thanking in advance
Regards,
Abhinay Verma
Greenhorn
Joined: Dec 13, 2004
Posts: 24
posted
0
null can be cast to any reference type without any side-effects. However, null is never an instance of any class. Therefore, null instanceof Object will return false
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
posted
0
The "<reference> instanceof <class>" operator works on the actual instance referred to by <reference>. Since a null reference has no class, it cannot be an instace of any class, and it always returns false.
[ Disabled smilies. ] [ February 21, 2005: Message edited by: David Harkness ]