Skip to content
← Back to Community
Is there a way to enable assertions for Java?
Profile icon
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
Profile icon
StoyanKostadino
Profile icon
JamiLittle
Profile icon
PeterLocke
Profile icon
CodyStingley
Comments
hotnewtop
Profile icon
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

Profile icon
CodyStingley

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