This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About assertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About assertion" Watch "About assertion" New topic

About assertion

Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 166
Hello All,

I do not understand why the following answer is correct?
Q: Given an assert statement - assert exp1 : exp2;
A: Whenever assertions are enabled, exp1 always get evaluated

So I write a program to test it.

I run the above program with "java -ea -cp . TestAssert", it prints "AssertionError: b != b2"
However, I use "java -cp . TestAssert", it only prints "No AssertionError" but without "call me() ..." ?

Is the anwser wrong ?

Thanks in advance!!
Geoffrey Vlassaks

Joined: May 12, 2004
Posts: 24
Assertions are disabled by default. You have to enable them by yourself (fe. using -ea). So for the second run statement, all the "assert" code will be skipped..

Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 166

Consider Paul's rocket mass heater.
subject: About assertion