日期:2014-05-20  浏览次数:20761 次

assertion问题
public   class   AssertionExp   {
public   void   aMethod(int   value)   {
assert   value   > =   0;
System.out.println( "OK ");
}

public   static   void   main(String[]   args)   {
AssertionExp   foo   =   new   AssertionExp();
System.out.print( "aClass.aMethod(   1   ):   ");
foo.aMethod(1);
System.out.print( "aClass.aMethod(   -1   ):   ");
foo.aMethod(-1);
}
}
用Eclipse3.2运行时为什么输出是:
aClass.aMethod(   1   ):   OK
aClass.aMethod(   -1   ):   OK


------解决方案--------------------
是不是参数的原因?
java –ea:类名

------解决方案--------------------
你使用了断言,当然会这样
------解决方案--------------------
断言必须使用ea参数启动,否则会被忽略。
参看楼上。

------解决方案--------------------
http://www.ibm.com/developerworks/cn/java/l-javaassertion/index.html