Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

? Operator Does Not Work

Tags:

java

operators

How come this is not possible? I am getting illegal start of expression.

(s1.charAt(i) == ' ') ? i++ : break;
like image 478
sudo Avatar asked Oct 23 '10 07:10

sudo


1 Answers

The thing to understand here is that the ?: operator is used to return a value. You're basically calling a function that looks like this in that line:

anonymous function:
    if(s1.charAt(i) == ' '):
        return i++;
    else:
        return break;

Makes no sense, right? The ?: operator was only designed as a shorthand for if/else return statements like the above, not a replacement of if/else altogether.

like image 63
doppelgreener Avatar answered Sep 28 '22 07:09

doppelgreener