mercredi 17 juin 2015

final modifier leads to change in flow of control

I have the following code in which the if block executes depending upon whether a the String offline is declared final or not...

[final] String offline = _page.getProperty("offline");

if (!TextUtils.isEmpty(offline) && offline.equals("true")) {
.  -> here if offline is declared final
.
} else {
.  -> here if offline is not declared final
}

...if offline is null.

It is clear that !TextUtils.isEmpty(offline) is short-circuiting offline.equals(..) because I don't get a NullPointerException.

The only way for short-circuit to work in this case is for the first part to always evaluate to false. I don't understand how to figure this out. Please help.

Compiled using javac 1.7.0_79, Android SDK 19

Aucun commentaire:

Enregistrer un commentaire