Assertions check correctness by way of assumptions and invariants. The keyword is assert.
There are two forms:
assert weight < 120;
Or:
assert weight < 120 : "Weight cannot be more than 120";
Assertions should not be used in production and are enabled with the virtual machine argument -ea.
Assertions should look for programming errors and not user inputs.
Assertions are used to design better code and spot more easily bugs. They are widely used in "design by contract" programming.
Assertions should tests:
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.