Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instanceof

 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



It compiles fine but there is no output. I expected at least "inside int test".
I am passing an int[] array into the method, checking if it is an instance of int[], and was pretty sure it will be true.

what is the problem here?!
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although null is a valid value for any reference variable, it is not an instance of any type. In other words, Java defines "null instanceof Type" to always be false, for any class or interface Type.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic