- Avoid using
assert
in Java production code as assertion is not turned on by default. Throw exception instead (since assert is just a syntax sugar of throwing exceptions).
The most important thing to remember about assertions is that they can be disabled, so never assume they'll be executed.
Therefore keep the followings things in mind when using assertions: