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.
About Question enthuware.ocpjp.v21.2.4051 :
Moderator: admin
-
- Posts: 21
- Joined: Fri Feb 07, 2025 5:36 pm
- Contact:
-
- Site Admin
- Posts: 10436
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v21.2.4051 :
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!
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!
Who is online
Users browsing this forum: No registered users and 105 guests