Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : A words : assertions.
For (2) you use asserts which can be turned off once you are sure the code is solid.
For (3) you trust the run time array subscript out of bounds and null pointer checking.
Bertrand Meyer in Eiffel pioneered the use of structured assertions in a system he called Programming By Contract. These serve both to document the preconditions (require) on parameters coming into a method, and the guaranteed characteristics of the result (ensure). Unfortunately, Java still does not support them. They can be crudely added with the JaWa preprocessor.
Java 1.4.1+ has a feature Sun calls assertions but they are so pathetic they don't deserve the name. It is as though Sun wanted to claim that Java has assertions without doing any work to implement them and not caring if the final product was actually of any use. If Sun wants to try again, they should look at how Eiffel assertions work.
They are new language feature, not a new class. Read about
assert a > b : "a must be bigger than b";
The second expression can be anything you would feed to printLn or it can be left out.
To mark a place in your code you should never get, you can code an assertion that always fails like this:
assert false : "Fell out bottom of loop without finding elt.";
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 1429. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/assertions.html | J:\mindprod\jgloss\assertions.html | |||