If assertions are enabled, the code will figure it out, but it will not do it in a proper way! It will always throw an AssertionError if assertions are enabled and will never reach the if-statement. Line 2 of the code should be modified to:The only case where this could be justified is when you are trying to find out whether or not assertions are enabled in your code:Code: Select all
boolean enabled = false; assert enabled == true; if(enabled) System.out.println("Assertions are enabled") else System.out.println("Assertions are disabled")
Code: Select all
assert enabled = true;
Kind regards,
Martijn