-1

Assert statement should throw a exception , right? but instead it prints print statement below. What might be the reason behind this? I also used Scanner class for this to check at runtime but it shows same result.

int number = 6;
assert number == 8;
System.out.println("print something");
Faizan Ahmad
  • 355
  • 3
  • 14
  • you can refer to below link as to how to enable assertions in Eclipse IDE https://stackoverflow.com/questions/11415160/how-to-enable-the-java-keyword-assert-in-eclipse-program-wise – Sachin May 05 '19 at 10:57

1 Answers1

3

Assert are disabled unless you pass the -ea (enable assertions) command line option to the JVM.

For Eclipse, you may follow this link: Setting execution arguments

Add -ea to the VM arguments:

VM Arguments: Values meant to change the behavior of the Java virtual machine (VM). For example, you may need to tell the VM whether to use a just-in-time (JIT) compiler, or you may need to specify the maximum heap size the VM should use. Refer to your VM's documentation for more information about the available VM arguments.

Alternatively, this can be done widely on the JRE: Adding a new JRE definition

In the Default VM Arguments field, you can add/edit the default arguments that will be passed to the VM when launching.

NoDataFound
  • 11,381
  • 33
  • 59