Constraint von Hand gemacht

/**
 * Klasse mit int-Wert, der
 * nicht negativ (x < 0)
 * sein darf.
 */
public final class NonNegativeInt {

  /** constraint-geschützter int Wert */
  public final int value;

  /** Konstruktor. */
  public NonNegativeInt( final int value ) {
    if ( value < 0 ) {
      throw new IllegalArgumentException(
          "value is negative " + value );
    }
  }

  // TODO hashCode, equals, toString
}
Anfang weiter