This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assert question

 
patrick avery
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Master Exam I came across a question with some code containing 2 assert statements. The text of the question did not reference the assert statements and did not indicate that asserts had been enabled...it just asked "What is the result?"

2 questions:

1 - for the exam if the code contains assert statements but nothing is said about whether or not they are enabled should we assume that they are not?

2 - if asserts are not enabled does this mean they will not be executed or only that they will execute but not cause an assert exception?
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Patrick,

1. In Java 1.6 assertions are enabled by default at compile time, but at runtime they are disabled unless you enable them explicitly.

2. When you don't enable assertions at the java command line that means the JVM will bypass assertion code (it is as if it hadn't been coded.)
[ December 30, 2008: Message edited by: Ruben Soto ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic