Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assertions in java 6

 
mrs nair
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there ,
i was wondering what the output should be for the following code ,
public static void main(String[] args) {
// TODO Auto-generated method stub
int age =18;


assert(age < 18);
System.out.println("hello here......................");
}
surely an assertion error and the "hello here" shouldn't be displayed ..i am sorry but this dosent happen when i run it on eclipse indigo and i use jdk 1.6.0_27.can anyone figure out where's the bug?
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mrs nair wrote:hi there ,
i was wondering what the output should be for the following code ,
public static void main(String[] args) {
// TODO Auto-generated method stub
int age =18;


assert(age < 18);
System.out.println("hello here......................");
}
surely an assertion error and the "hello here" shouldn't be displayed ..i am sorry but this dosent happen when i run it on eclipse indigo and i use jdk 1.6.0_27.can anyone figure out where's the bug?


Hello Mrs Nair... Assertions are disabled by default, if you intend to enable assertions in other for the above code to throw an assertion error, you can simply use the command lines and navigate to the .class file
or the packge directory and run the class with the -ea (enable assertions) flag, i.e 'java -ea com.xxx.YourClass'...

HTH

Ikpefua
 
Sebanti Sanyal
Ranch Hand
Posts: 58
C++ Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To enable assertion on Eclipse, select from Menu Bar,Run ->Run Configuration->Arguments tab.Now type -ea in VM arguments and click on Apply.Now you'll get the AssertionError when you run. I am using Mac OS X 10.5.8.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic