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

Dan's questions on assertions: inconsistent?

 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are two questions on assertions from Dan's single topic exam:

The correct answers are a, d, f, h for q. 15 and b, d, e for q. 17. Option f states the same in both, but it doesn't show up in q. 17 as correct. However, the real problem is under what circumstances using assertions is appropriate for checking a precondition
Here's what Programming with Assertions states:

Do not use assertions to check the parameters of a public method. An assert is inappropriate because the method guarantees that it will always enforce the argument checks. It must check its arguments whether or not assertions are enabled. Further, the assert construct does not throw an exception of the specified type. It can throw only an AssertionError.
You can, however, use an assertion to test a nonpublic method's precondition that you believe will be true no matter what a client does with the class. For example, an assertion is appropriate in the following "helper method" that is invoked by the previous method...

I think, option f in both questions needs to be defined clearer to comply with assertions usage rules.
[ November 07, 2003: Message edited by: Vad Fogel ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic