Class Assert
java.lang.Object
|
+----Assert
- public class Assert
- extends Object
A facility for asserts based on the C/C++ macro.
Note that the java type system requires several overloaded
assert methods.
Expanded from java.sun.com Tech Tips, February 17, 1998.
Java 1.1 Implementation
-
Assert()
-
-
abort()
- Abort program with a stack trace.
-
abort(String)
- Print message and abort program with a stack trace.
-
assert(boolean)
- Boolean assertions.
-
assert(boolean, String)
- Boolean assertions.
-
assert(double)
- Float and double assertions.
-
assert(double, String)
- Float and double assertions.
-
assert(long)
- Byte, char, short, int, and long assertions.
-
assert(long, String)
- Byte, char, short, int, and long assertions.
-
assert(Object)
- Reference assertions.
-
assert(Object, String)
- Reference assertions.
Assert
public Assert()
abort
public static void abort()
- Abort program with a stack trace.
abort
public static void abort(String description)
- Print message and abort program with a stack trace.
- Parameters:
- String - a description of the fatal error.
assert
public static void assert(boolean b)
- Boolean assertions.
If the argument is false then a stack trace is printed
and the program is exited.
- Parameters:
- boolean - the asserted condition.
assert
public static void assert(boolean b,
String description)
- Boolean assertions.
If the first argument is false then a description and a stack trace
are printed and the program is exited.
- Parameters:
- boolean - the asserted condition.
- String - a description of the fatal error.
assert
public static void assert(long l)
- Byte, char, short, int, and long assertions.
If the argument is equal to zero then a stack trace is printed
and the program is exited.
- Parameters:
- long - the asserted condition.
assert
public static void assert(long l,
String description)
- Byte, char, short, int, and long assertions.
If the first argument is equal to zero then a description
and a stack trace are printed and the program is exited.
- Parameters:
- long - the asserted condition.
- String - a description of the fatal error.
assert
public static void assert(double d)
- Float and double assertions.
If the argument is equal to zero then a stack trace is printed
and the program is exited.
- Parameters:
- double - the asserted condition.
assert
public static void assert(double d,
String description)
- Float and double assertions.
If the first argument is equal to zero then a description
and a stack trace are printed and the program is exited.
- Parameters:
- double - the asserted condition.
- String - a description of the fatal error.
assert
public static void assert(Object ref)
- Reference assertions.
If the argument is equal to null then a stack trace is printed
and the program is exited.
Example usage:
Object p = f() ; Assert.assert(p) ; // checks that p is not null
- Parameters:
- Object - the asserted condition.
assert
public static void assert(Object ref,
String description)
- Reference assertions.
If the first argument is equal to null then a description
and a stack trace are printed and the program is exited.
Example usage:
Object p = f() ; Assert.assert(p, "bang") ; // checks that p is not null
- Parameters:
- Object - the asserted condition.
- String - a description of the fatal error.