|
-
Sep 25th, 2008, 01:05 PM
#1
Thread Starter
Member
[RESOLVED] use of assertion
what is the use of assertion when i can use if statement to get the same result.
could any one please tell me.
thank you.
-
Sep 25th, 2008, 08:57 PM
#2
Re: use of assertion
The assert statement evaluates the expression and throws an AssertionError if the value returned is false.. Thats not what if statements are for.
Assertions are mostly used in Testing, besides they can be turned on or off before starting the Application
Further reading
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Sep 26th, 2008, 06:03 AM
#3
Thread Starter
Member
Re: use of assertion
yeah thanks, now i understood. it mostly used in a development phase. where i would want my application stops if any error occurs. but i can disable it while distributing app.
-
Sep 26th, 2008, 08:19 AM
#4
Re: [RESOLVED] use of assertion
By default, assertions are disabled at runtime. To enable assertions, use the switch -enableassertion (or -ea) as follows:
prompt> java -ea AssertionTest
prompt> java -enableassertion AssertionTest
Where AssertionTest is a class name
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|