Java Reference
In-Depth Information
16.14. Controlling Assertions at Runtime
In Chapter 12 you learned about assertions and how they can be turned
on or off through command-line options that you pass to the virtual ma-
chine (see Section 12.10 on page 300 ) . You can also affect assertion
evaluation from running code, although this is rarely required. You will
probably need to do this only if you are writing a harness for running oth-
er code and must provide your users with options to manage assertions.
Such manipulation is done with methods on ClassLoader :
public void setDefaultAssertionStatus(boolean enabled)
Sets the default assertion status for all classes loaded in this
loader. Child loaders are not affected, whether they exist at
the time this method is invoked or after. The initial default as-
sertion status for a class loader is false .
public void setPackageAssertionStatus(String packageName, boolean en-
abled)
Sets the default assertion status for all classes in the given
package and it's subpackages that are loaded in this loader. A
null package name means the unnamed package for this class
loadersee Chapter 18 , page 468 .
public void setClassAssertionStatus(String className, boolean en-
abled)
Sets the default assertion status for the given class and for
all its nested classes when loaded in this loader. You can only
name top-level classes; nested classes are turned off and on
via their enclosing class.
public void clearAssertionStatus()
 
Search WWH ::




Custom Search