• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Design FAQ of Assertion

 
Stephen Suen
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I read Design FAQ of Assertion, I found such an entry(the last entry on the bottom of the page):

8. Why does an assert statement that executes before its class is initialized behave as if assertions were enabled in the class?

Few programmers are aware of the fact that a class's constructors and methods can run prior to its initialization. When this happens, it is quite likely that the class's invariants have not yet been established, which can cause serious and subtle bugs. Any assertion that executes in this state is likely to fail, alerting the programmer to the problem. Thus, it is generally helpful to the programmer to execute all assertions encountered while in this state.


I know the fact that a class'e constructors and methods can run before its initialization complete, but I still don't understand what the FAQ says.

Anyone can help me please?

Stephen Suen
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note: The source for the above quote is...

http://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html
 
Stephen Suen
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:
Note: The source for the above quote is...

http://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html


Sorry I forgot to post the link, and thank marc weber help me to do it.
 
Stephen Suen
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I found the answer. See:

http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.10
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic