Ask coding questions

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

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!


Answered by abc3354 (229) [earned 5 cycles]
View Answer
abc3354 (229)

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 (2)

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