Why does this basic Java boolean expression not work? -


why not compute in java (v1.8). seems logical me....

boolean banana = true; (banana == true || false) ? system.out.println("true") : system.out.println("false"); 

output message: error: java: not statement

the ternary conditional operator must return value. second , third operands can't statements don't return anything. must expressions return value.

you switch :

system.out.println(banana ? "true" : "false"); 

note banana == true || false equivalent banana == true, equivalent banana banana boolean type.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -