Page 1 of 1

About Question enthuware.ocpjp.v8.2.1565 :

Posted: Fri Oct 09, 2015 3:50 am
by Martyjee
The explanation contains the following
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")
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:

Code: Select all

assert enabled = true;
(assignment!). In this case 'enabled' will only be set to true if assertions are enabled, because otherwise line 2 will not be executed!

Kind regards,

Martijn

Re: About Question enthuware.ocpjp.v8.2.1565 :

Posted: Fri Oct 09, 2015 4:06 am
by admin
You are right. Fixed.
thank you for your feedback!