assert is available in 1.4 only. By default, it is disabled
at runtime. If you don't specify the source at runtime, then the compiler will complain. Hence, given a file that has "assert" keyword in it, to compile you need to do this:-
javac -source 1.4 testAssert.java
if your old program is using the word assert as a variable name, then to make the compiler NOT complaining about it, do this:-
javac -source 1.3 testAssertNotKeyword.java
how do you enable assertions at runtime?
java -ea testAssert
voila! The need thing about assertion is you can control which package(s) need to have assertion enabled and which one is not.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.