jeudi 23 juillet 2015

Java 3 tier if statement short hand does not work as intended

Why does this work:

if(name.equals("email_stub")) {
    if(emailStub == "")
        emailStub = results.getString("text");
} else if(name.equals("fax")) {
    if(fax == "")
        fax = results.getString("text");
} 

But without the first tier of brackets, it will not work and instead fail to logically separate the if statements. i.e. it will never go beyond the first if statement and won't work as intended.

if(name.equals("email_stub"))
    if(emailStub == "")
        emailStub = results.getString("text");
else if(name.equals("fax"))
    if(fax == "")
        fax = results.getString("text");

Thanks.Thought it weird when I ran into this issue.

Aucun commentaire:

Enregistrer un commentaire