Can ternary operators be used instead of simple if else statements ?
eg. (i>5)?doSomething() : DoSomethingElse();
Ive tried coding similar to this but with no success. Can terenary operators only be used to assign values ?
eg. booleanVar = (j>5)?true:false;
is there any other way to do the same logic as a simple if else statement ?
(disabled smily) [ July 26, 2006: Message edited by: Barry Gaunt ]
Joined: Jul 15, 2006
ha, i dont think any compiler will compile the smiley face, replace that with :
Joined: May 23, 2006
Hey You can use the teneray operators instead of a If-else statement
Joined: Feb 07, 2005
No, you can't use the ternary operator like that.
This is from the Java Language Specification.
Note that it is a compile-time error for either the second or the third operand expression to be an invocation of a void method. In fact, it is not permitted for a conditional expression to appear in any context where an invocation of a void method could appear (�14.8).