Java Brainteaser #1
I was reading some blogs tonight and came across some interesting Java brainteasers. Here's one of them.
In certain circumstances the following Java code will compile and run. What are those circumstances?
if(this) {
System.out.println("this is, inded, true!");
}
I'll give you a hint, they require a Java 5 compiler.
UPDATE: Answer in the comments.
1 comment:
If the code snippet appeared within the java.lang.Boolean class, the this variable will be auto-unboxed into a boolean and booleanValue() will be called.
I got this brainteaser from here.
Post a Comment