Dealing with completeness (type coverage) in pattern labels for switch 2 – Objects, Immutability, Switch Expressions, and Pattern Matching

Now, the selector expression can be any type which means that the total pattern Vehicle v is not total anymore. While Vehicle v becomes an optional ordinary pattern, the new total pattern is case Object obj. This means that we can cover all possible values by adding the default label or the case Object obj […]

Dealing with completeness (type coverage) in pattern labels for switch – Objects, Immutability, Switch Expressions, and Pattern Matching

61. Dealing with completeness (type coverage) in pattern labels for switch In a nutshell, switch expressions and switch statements that use null and/or pattern labels should be exhaustive. In other words, we must cover with explicit switch case labels all the possible values. Let’s consider the following example: class Vehicle {}class Car extends Vehicle {}class […]

© 2024 nickshade Please read our Terms and Privacy Policy. We also use Cookies.