Question

I faced with assertion in java

public static void main(String[] args) {
        assert true;
        assert false;
    }

I don't understand why I don;t see assertion error at this case?

What do this code snippet do?

Was it helpful?

Solution

Assertions need to be enabled when you launch the JVM e.g.

$ java -ea ...

See the doc for more details.

By default, assertions are disabled at runtime. Two command-line switches allow you to selectively enable or disable assertions.

To enable assertions at various granularities, use the -enableassertions, or -ea, switch

Note that you can enable/disable per class/package if you require.

As to how you perform this with IDEA, you need to modify the VM options for your particular run/debug configuration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top