Ask coding questions

← Back to all posts
Is there a way to enable assertions for Java?
CodyStingley

Hey Repl!

I'm teaching a lesson this week where students need to work with assertions in Java. It looks like by default assertions are ignored by your Java compiler. Is there a way I/we can enable assertions? See attached Repl for an example.

Thank you!

Cody

Answered by abc3354 [earned 5 cycles]
View Answer
Voters
JamiLittle
PeterLocke
CodyStingley
Comments
hotnewtop
abc3354

Hi !

I found on the internet that java needs a "-ea" argument to run the exceptions.
You can have a special execution with a .replit file.

I made that for you here

CodyStingley

Thank you, @abc3354! Had heard about the -ea argument but didn't know anything about .replit files. You're amazing!