This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
By the way, it's generally not a good idea to use assertions for checking the preconditions of public methods or constructors. You should throw an IllegalArgumentException (run-time exception) instead, so that the public contract is enforced whether assertions are turned on or not.
Use assertions for checking the preconditions of non-public methods, or for checking internal consistency and post-conditions.
Joined: Oct 14, 2001
To answer your original question, to run the code with assertions use the -ea (or -enableassertions) switch when you run java.
Joined: Mar 05, 2005
yea I understand but i compiled with with this above my code:
and got a compile time error. I was just wondering if there was a simple if statement that I stated above that would work?