• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What assumption to make on assertion questions?

 
Rajeev Trikha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a question uses assert statements and the question says: 'What is the result? what should we assume regarding the fact whether assertions are enabled or not?

My concern is that by default the assertions are not enabled so even if the code says 'assert false' nothing will happen. The correct answer depends on the underlying assumption so just want to clarify.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally questions which involve assert statements are framed like this

"Given the following code

/*code*/

and the command used to run the program

java -ea MyClass

What will be the result"

So you don't have to make any assumptions. If the command is not given, you might find something in the question which says -> "assertions are enabled at runtime, what will be the result". If none of the two is given, then you can assume that assertions are not enabled at runtime...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic