Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Syntax error on token ":", * expected
public class TestAssert { public void methodA(int i){
assert (i>=0 : methodB());
System.out.pritnln(i);
}

public int methodB(){
System.out.println("The value must not be negative");
return 3;
}
/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
TestAssert test=new TestAssert();
test.methodA(-10);
}}

解决方案 »

  1.   

    assert BooleanExpression : anyExpression
    assert (i>=0 : methodB());
    错了,
    应该是 assert (i>=0) : methodB();
      

  2.   

    好像要这样assert i >= 0 : methodB();
      

  3.   

    这样时,会弹出以下异常信息
    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Syntax error on token "assert", ( expected
    Syntax error, insert ";" to complete BlockStatements
    Syntax error, insert "AssignmentOperator ArrayInitializer" to complete ArrayInitializerAssignement
    Syntax error, insert ")" to complete Expression调试看看
      

  4.   

    JAVA是从JDK1.4才开始支持断言的估计是你的jdk版本过低吧
      

  5.   

    谢了,各位,我用的Eclipse,是因为没有配置好的原因