Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java assert gives strange results

what should the following java code do?

public class foo{
    public static void main(String[] args){
        boolean mybool=false;
        assert (mybool==true);
    }
}

Should this throw an assertion error? and if not why not? (I'm not getting any errors!)


1 Answers

When running the program, you have to enable assertions in the Java VM by adding '-ea' to the command line:

java -ea -jar myprogram.jar
like image 142
Michael Donohue Avatar answered Sep 11 '26 23:09

Michael Donohue