Can you give me a quick overview of support for assertions in JDK1.4?

Davanum Srinivas

Use assert keyword in your java code:

    if (i % 3 == 0) {
        ...
    } else if (i%3 == 1) {
        ...
    } else {
        assert i%3 == 2;
        ...
    }
When compiling the code you need to specify 1.4 in the command-line:
javac -source 1.4 MyClass.java
Then when you run the code you can switch assertions on by using:
java [ -enableassertions | -ea  ] [:<package name>"..." | :<class name> ]
There is a switch for disabling assertions too:
java [ -disableassertions | -da ] [:<package name>"..." | :<class name> ]
You can find more information at:
http://java.sun.com/j2se/1.4/docs/guide/lang/assert.html
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact