Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return value syntax in java

Tags:

java

return

I am not really sure what this method does, or better I am not sure what " : " means. Can someone please help me understand?

private int guess( )
 {
      return isTrue( ) ? A : isFalse(  ) ? B : neither( ) ? C : D;
 }
like image 457
FranXh Avatar asked Jul 11 '26 13:07

FranXh


1 Answers

This is a case of nested ternary operators which have the form a ? b : c which evaluates to:

if (a) then b, else c

So your question breaks down to this:

if (isTrue()) {
    return A;
} else if(isFalse()) {
    return B;
} else if(neither()) {
    return C;
} else {
    return D;
}
like image 72
逆さま Avatar answered Jul 13 '26 10:07

逆さま