Argument checking is typically part of the published specifications (or contract) of a method, and these specifications must be obeyed whether assertions are enabled or disabled. Another problem with using assertions for argument checking is that erroneous arguments should result in an appropriate runtime exception (such as IllegalArgumentException, IndexOutOfBoundsException, or NullPointerException). An assertion failure will not throw an appropriate exception.
I know the answer. If you don't understand it, you need to explain what it is about the concept you don't understand. Your question was this: "But assertion Can't Be Applied For Checking Public Method's argument...Please Explain Why?". The explanation as to why is contained in the material I posted. If you're still confused by it, explain what it is you don't understand.If You Don't Know Answer Simply Don't Answer.......
First, I have no way of knowing you read the quote I posted from the tutorial. Second, the quote I posted elaborates on and explains the quote you posted. What is it that you don't understand about it?What Is The Meaning Of Posting A Quote From The Same Site Whose Reference And Qoute Has Been Given By Me !
Hey Mr. Anderson Who Are You To Say .......
I Am Not A Member Of This Forum Due To You.And The Question May Be Nonsense To You So Better Don't Answer.
If You Don't Know The Answer Please Don't Beat Around The Bush.
IN Above [assertsEnabled = true] is Not Evaluating To true Why?
Boolean assignment expressions evaluate to the right-hand value (i.e., the expression "assertsEnabled = true" evaluates to true). If assertions are enabled, not only will the expression pass the assertion, but it will also assign true to the variable. This will cause the if() condition to fail, and no RuntimeException will be thrown. It's a simple way of making sure that assertions are enabled.But Mr.Steve The Statement Following assert Should evaluate To True.....but Here It Is An Assignment Only.Why?
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Originally posted by agrah upadhyay:
SUN Tutorial Says That
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.
The Above Mentioned Statement Should Be Applied Both For public as Well AS private Methos Because Both Of Them Check Their Arguments But assertion Can't Be Applied For Checking Public Method's argument
Please Explain Why?
**********************
Agrah
[ September 23, 2005: Message edited by: agrah upadhyay ]
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Originally posted by agrah upadhyay:
ONE MORE THING
******************************************************************
Requiring that Assertions are Enabled
Programmers of certain critical systems might wish to ensure that assertions are not disabled in the field. The following static initialization idiom prevents a class from being initialized if its assertions have been disabled:
static {
boolean assertsEnabled = false;
assert assertsEnabled = true; // Intentional side effect!!!
if (!assertsEnabled)
throw new RuntimeException("Asserts must be enabled!!!");
}
Put this static-initializer at the top of your class.
*****************************************************************
The Above Has Beeen Given In SUN 's Official Site.I Want To Ask In Third Line Which Is:
assert assertsEnabled = true;
IN Above [assertsEnabled = true] is Not Evaluating To true Why?
********************************************
Thanx
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
What? What, what, what? What what tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|