C:\Users\Malvolio>jshell
| Welcome to JShell -- Version 9.0.1
| For an introduction type: /help intro
jshell> assert(false)
jshell>
How can I make the Java Shell throw an AssertionError when an assert fails?
To configure assertion options one must use either the -ea or -da command line flags to enable or disable assertions with the command line tool: “java”. For example, “java -ea Assert” where Assert is a java class file. You may also specify a specific class or package as follows.
Assertions are not enabled by default, because they should be always fullfilled. You enable them to test for that, but then you "know" (as far as you can know) that they are not violated. So you don't need to check the conditions (which might be performance intensive) every time in production code.
Enabling and Disabling AssertionsBy default, assertions are disabled at runtime. Two command-line switches allow you to selectively enable or disable assertions. Enables or disables assertions in all classes except system classes.
Start it with the command option:
jshell -R -ea
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With