Platinum Partner
java

Interesting Java Language Puzzle

We ran into an unexpected result as part of Java's auto boxing feature. At least I think it is related to auto boxing. See the following code snippet
package com.foo;

public class AutoBoxTest {

	public static void main(String[] args) {
		Boolean abc = new Boolean(false);
		setMe(getThisValue() || abc == null? false: abc); 
	}
	
	static public Boolean getThisValue() {
		return new Boolean(true);
	}
	static public void setMe(Boolean pValue) {
		System.out.println("Value is : " + pValue);
	}
}

The result? Value is : false

Huh? It turns out changing the call to setMe() as follows "fixes" the issue, I'd just like to know if anyone can explain why?

   Boolean abc = new Boolean(false);
   setMe(getThisValue() || (abc == null? false: abc)); 

The result is: Value is : true Strange.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}