SE450: Assertions: Enabling and Disabling assertions [5/24] ![]() ![]() ![]() |
To enable your source to contain assertions, compile your source as follows:
javac -source 1.4 MyClass.java
To enable assertions at runtime, you can do the following:
java [ -enableassertions | -ea ] [:<package name>"..." | :<class name> ]
The ... is used to enable assertions in the package. A single argument of ... enables assertions for the default package.
To disable asserations at runtime, you can do the following:
java [ -disableassertions | -da ] [:<package name>"..." | :<class name> ]
Where the ... is used the same as above.
The -ea and -da flags can be used in combination to fine tune the classes that have assertions enabled.
To enable or disable assertions in the systems classes, use
java [ -enablesystemassertions | -esa ]and
java [ -disablesystemassertions | -dsa ]
You can enable assertions in individual systems classes with the -ea and -da flags above, but with the no-arg form, system classes are not enabled by default.