Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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; 
}
like image 205
anon Avatar asked Sep 16 '25 02:09

anon


1 Answers

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.

like image 160
Freiheit Avatar answered Sep 19 '25 05:09

Freiheit