Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is "obj instanceof Object" false in Java?

Tags:

java

Consider

 Object obj = ....;
 System.out.println(obj instanceof Object);

What should obj be so that the answer is false (Any other option other than null)

like image 572
Ajay Avatar asked Nov 27 '22 20:11

Ajay


1 Answers

Is this a trick question?

Object obj = new Object() {{ System.out.println(false); System.exit(0); }};
System.out.println(obj instanceof Object);
like image 142
Tom Hawtin - tackline Avatar answered Nov 29 '22 10:11

Tom Hawtin - tackline