Originally posted by Champ Me:
Hi Rimi
Well in case of ternary like in
//1
String s3 = b?s1:s1+s2;
Right hand part can be resolved as
if(b){
s1;
}
else{
s1+s2;
}
and the result of the if condition is assign to the s3 so we get //s3="Foo"
But in other case
//2
it will be resolved as
(
if(b){
s1;
}else{
s1;
}
) + s2;
the result of the if condition is resolved first and the result is concatenated with s2. and the final result is assign to the s4. That is why we get
//s4="FooBar"
Don't forget parenthesis has the highest precedence.
I Explain it in this form so that you have good understanding.
I hope you like it.
![]()