So how is the Java (@Android) ternary operator supposed to behave really ?
Check these simple examples:
boolean trigger = true;
String myStr_NOK = trigger ? "YES:" : "NO:"
+ " if trigger was TRUE"
+ " this is NOT visible :-o");
String myStr_OK = (trigger ? "YES:" : "NO:")
+ " if trigger was TRUE"
+ " this is visible as should.");
// I think the first comments missed this fact:
trigger = false;
String myStr_NOK = trigger ? "YES:" : "NO:"
+ " if trigger was FALSE"
+ " this IS concatenated AGAIN");
Now that is a masterpeace of Java logic, that my brain just refuses to swallow.
Do you REALLY have to encapsulate the ternary operator in Java (Android) in brackets, else you do not get the rest of composed string ?
See: myStr_NOK only contains "YES:", since the ternary operator was not in brackets ?
In this page, it clearly states, that no brackets are required. As I would rightfully expect. Quote:
Note that the parentheses in this example are optional, ...
EDIT: Let me re-phrase my Q: What does the standard say about ternary operator ? My observation is such, that withOUT parenthesis around the ternary operator, the further string concatenation is performed ONLY when expression is FALSE. If TRUE, it does not concatenate. Does anyone find this meaningful, obvious and expected behavior ?
And now my original Q that got downvotes: What am I getting wrong, or has the world just gone mad ?