John Java
John Java

Reputation: 153

Assertion Error issue

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);  
    }  
}  

Upvotes: 1

Views: 176

Answers (2)

Vinayak Pingale
Vinayak Pingale

Reputation: 1315

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

Upvotes: 1

René Link
René Link

Reputation: 51483

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";

Upvotes: 1

Related Questions