Page 1 of 1

About Question enthuware.ocpjp.v21.2.4051 :

Posted: Mon Oct 06, 2025 1:35 pm
by giginar
option 5 is trying to say, Point p1 when p1.x()>p1.y() -> true, all the other cases are false?

and also, if as explanation says, "a case null branch does not affect the exhaustiveness of a switch", why option 3 says "This switch does not cover the possibility where p is null and is therefore not exhaustive." ? thanks.

Re: About Question enthuware.ocpjp.v21.2.4051 :

Posted: Tue Oct 07, 2025 2:03 am
by admin
The comment in option 3 is wrong. Option 3 is incorrect not because it doesn't have case null but because the compiler cannot execute the expressions given after the when clause and it cannot determine that the two expressions x>y and x<=y cover all possibilities. (The same reason for option 4) Thus, it cannot assume it to be exhaustive. It has nothing to do with null and should be updated.

It is true that a case null branch does not affect the exhaustiveness of a switch, which means, a switch statement/expression can be exhaustive even if it does not contain a path of execution when the switch variable is null.

This has now been updated.
thank you for your feedback!