Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About assertion

 
Jack Lau
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
Jack
 
Geoffrey Vlassaks
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

Greetz
 
Jack Lau
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

Jack
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic