anon
anon

Reputation: 51

Java assertions in IntelliJ IDEA Community?

How do I enable assertions in IntelliJ? My code compiles but the assertions do not show up anywhere on the output.

For example:

public static void main(String[] args) { 
    int someInt = 5;
    assert someInt > 5; 
    assert someInt <= 5; 
}

Upvotes: 4

Views: 3499

Answers (1)

Freiheit
Freiheit

Reputation: 8767

Based on this answer for Eclipse you need to pass a JVM option -ea to enable assertions in any JVM. It's not unique to any specific IDE.

For IntelliJ it looks like this in the run config: IntelliJ 2020.3 Run Dialog to enter ea option

Note that you may have to select "Modify Options" to make the JVM options input box visible to enter the -ea flag.

Upvotes: 10

Related Questions