What\'s wrong with this code:
void bark(boolean hamlet) {
hamlet ? System.out.println(\"To Bark.\") : System.out.println(\"Not to Bark\");
}
You can read why in the Java Language Specification, 15.25. Conditional Operator ? :
It is a compile-time error for either the second or the third operand expression to be an invocation of a void method.
You need to do as several of the other answers suggest, and apply the conditional operator to just the argument.