+ 3

What is the use of instanceof keyword in java?

20th Jul 2017, 4:11 PM
Viraj Singh
Viraj Singh - avatar
3 Respuestas
+ 4
Sort of. It doesn't tell you what type the variable is, rather, it returns you a boolean determining whether or not what is being compared is of the type you specified. Example/ Object a = "A string"; if(a instanceof String){ // true }
20th Jul 2017, 4:38 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
Now I understand, the name manifest itself "instance of" implies whether it is an intance(or object) of something or not. like ExampleClass s = new ExampleClass (); boolean GotIt = s instanceof ExampleClass; //true
20th Jul 2017, 4:48 PM
Viraj Singh
Viraj Singh - avatar
+ 1
indicating as parameter a variable name, it tells you which type (or which object) is the variable in question...
20th Jul 2017, 4:24 PM
2_3rr0r5
2_3rr0r5 - avatar