Jump to content

assert problem

- - - - -

  • Please log in to reply
3 replies to this topic

#1
denarced

denarced

    Programmer

  • Members
  • PipPipPipPip
  • 182 posts
I thought I understood asserts but clearly I'm missing something.
How is it possible that the following can print "I'm here":
assert title != null;
if(title == null)
     System.out.println("I'm here");
Anyone ?

If it's relevant, I'm using openjdk and netBeans on Ubuntu 10.10..

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Assertion is off by default in Netbeans:
To enable it:
  • Right click on the project icon in the Project panel at the left.
  • Select Properties at the bottom of the drop-down menu.
  • Click on the Run choice in the left panel.
  • In the VM Options text field at the right, enter "-ea" (Enable Assertion)


#3
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Did you make sure to tell your interpreter to not ignore assert statements? Remember that since the assert statement was not added until 1.4, the Java interpreter can still run into a lot of code that doesn't utilize asserts at all. As such, you have to give the Java interpreter a flag to signify the .class file uses asserts:
java -ea MyClassFile
That'll make it work. I tested this with OpenJDK on Ubuntu 10.10.

EDIT: wim dc already got this, gave NetBeans instructions too. I'm too used to using a text editor + command line. XD
Wow I changed my sig!

#4
denarced

denarced

    Programmer

  • Members
  • PipPipPipPip
  • 182 posts
Thanks for the quick responses.
Disabled by default and it didn't give any indications.. that'll leave a coder confused..




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users