might have to run this application a few times to see the assertion error, but first you
need to learn how to enable assertions, which I discuss later in this chapter.)
Caution Be careful when using an assertion statement to detect code that should
ever be executed. If the assertion statement cannot be reached according to the rules
set forth in The Java Language Specification, Third Edition, by James Gosling, Bill
available at ( http://java.sun.com/docs/books/jls/third_edition/
assert false; causesthecompilertoreportanerrorbecausetheinfiniteforloop
prevents the assertion statement from executing.
Design-by-Contract (see http://en.wikipedia.org/wiki/
port an informal design-by-contract style of development.
A precondition issomethingthatmustbetruewhenamethodiscalled.Assertionstate-
guments are legal. Listing 3-36 provides an example.
Listing 3-36. Verifying a precondition
public static void main(String args)
// Lotto 649 requires that six unique umbers be
int selectedNumbers = new int;
// Assign a unique random umber from 1 to 49 (inclus-
ive) to each slot
// in the selectedNumbers array.
for (int slot = 0; slot < selectedNumbers.length;