Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: change game 'name' to rock-paper-scissors

...

Never violate any of the first three conditions when implementing the compareTo() method. Implementations should conform to the fourth condition whenever possible.

Noncompliant Code Example (rock-paper-scissors)

This program implements the classic game of Roshamborock-paper-scissors, using the compareTo() operator to determine the winner of a game.

...

However, this game violates the notion of transitivity, because Rock beats Scissors, Scissors beats Paper, but Rock does not beat Paper.

Compliant Solution (rock-paper-scissors)

This compliant solution implements the same game, but does not use the Comparable interface.

...