1

I have posted this elsewhere, no solution yet, so posting it here as well. The below mentioned code is not throwing an assertion error as I expected it to since num is less than 5. Hope someone can advise. Thank you.

public class Wrong {  
public static void main(String[] args) {      
    Wrong wrong = new Wrong();            
    wrong.methodE(3);                 
    }     
    //AssertionError  
    void methodE(int num)  
    {  
        assert(num>5);  
    }  
}  
John Java
  • 153
  • 1
  • 3
  • 8
  • Answers below covered how to fix your particular issue but for more on `assert` in Java check out this thread: http://stackoverflow.com/questions/2758224/assertion-in-java – Durandal Jan 18 '14 at 07:30

2 Answers2

1

I guess you forgot to enable assertions.

Run the jvm with the -ea argument.

java -ea ...

you should also consider to provide an assertion error message, e.g.

assert num > 5 : "arg num must be greater than 5";
René Link
  • 48,224
  • 13
  • 108
  • 140
1

If you are using Eclipse go to Run--> Run Configuration --> VM Argument ---> Type -ea.

Vinayak Pingale
  • 1,315
  • 8
  • 19