I want to print a sentence like:
boolean someSetting = true;
System.out.println("Running experiment " + (someSetting)? "on" : "off");
Obviously this won't compile. Is there any other suggestion to do this?
add brackets around it to evaluate that expression to String
value
System.out.println("Running experiment " + ((someSetting)? "on" : "off"));
without brackets it tries to contact (+
) String
and boolean
and puts it as a conditional expression which is invalid
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments