Results 1 to 4 of 4

Thread: [RESOLVED] use of assertion

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    54

    Resolved [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.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    54

    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.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
  •  



Click Here to Expand Forum to Full Width