Search code examples
javaassert

Difference between java ' assert 'and ' if () {} else exit;'


what is the difference between java assert and if () {} else exit;?

can i just use if () {} else exit instead of assert ?


Solution

  • A bit of google maybe ?

    " The main thing you should keep in mind is that the if-else statement should be used for program flow control and the assert keyword should only be used for testing purposes. You should never use asserts to actually perform any operation required for your application to work properly. According to Sun's official Java documentation: "Each assertion contains a boolean expression that you believe will be true when the assertion executes." "

    Read more: http://wiki.answers.com/Q/What_is_the_difference_between_assert_keyword_and_if_keyword_in_java#ixzz1v2GGfAhq