|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 5 of 5
public class Pathological
{
private String ping( boolean test )
{
System.err.print( "ping ... " );
assert test : pong( test );
return null;
}
private String pong( boolean test )
{
System.err.print( "pong ... " );
assert test : ping( test );
return null;
}
public static void main( String[] args )
{
Pathological pathological = new Pathological();
System.err.println( "Pathological.ping( false ): " );
pathological.ping( false );
}
}
Though highly stylized, this example hints at the dangers of writing complex and oblique assert statements.
Assertions are an important addition to the Java programming language. By using assertions, developers can clearly demark the boundaries of acceptable program behavior.
This article exhaustively details the mechanics of using J2SE 1.4's assertions. Fortunately, you only need to digest most of these sticky details once. Using the simple assertion facility is relatively straightforward, so you can quickly add assertions to your development routine. Regrettably, neither the J2SE 1.4 compiler nor its runtime system enable the assertion facility by default. Each requires new command-line switches.
Part 2 of this article will discuss the methodological issues regarding assertions and how the Java assertion facility compares to Design by Contract. It also challenges the convention of using the Java exception mechanism for handling argument checking in public methods. Until then, remember to be assertive with your assertions.
Read more about Core Java in JavaWorld's Core Java section.