Search This Blog

Saturday 15 March 2014

Assertion In Java

Assertion includes a Boolean expression. If the Boolean expression evaluates to false AssertionError is thrown. Assertion helps a programmer to debug the code effectively.

Assertion code is removed when the program is deployed. Below is a code snippet which checks if inventory object is null.


Inventory objInv = null;
// ...
// Get your inventory object reference here
// ...
// Use assert to check if the object is null
// by any chance
assert objInv != null;

No comments:

Post a Comment