Why doesn’t this method work? Java ternary operator

Ternary operators can’t have statements that don’t return values, void methods. You need statements that have return values.

You need to rewrite it.

void bark(boolean hamlet) {
     System.out.println( hamlet ? "To Bark." : "Not to Bark" );
}

Leave a Comment