Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Instanceof  RSS feed

 
miria joseph
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one explain me what is the function of instanceof keyword in java.?




Thanks in advance.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"miria,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names with a first and a last name. You can edit your display name here. Thank you for your prompt attention!

Basically, ref instanceof Type is true if "ref" could be cast to Type without a ClassCastException. Otherwise, it's false. See JLS 15.20.2 for details.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!