I don't know if you know but using the latest version of the source,
this code does not compile.
sealed interface Vehicle {}
record Car(String owner, String color) implements Vehicle {}
record Bus(String owner) implements Vehicle {}
public static void example2() {
var vehicles = List.of(
new Car("Bob", "red"),
new Bus("Ana")
);
for(var vehicle: vehicles) {
switch(vehicle) {
case Car car -> System.out.println("car !");
case Bus bus -> System.out.println("bus !");
//default -> throw new AssertionError();
}
}
}
PatternMatching101.java:25: error: the switch statement does not cover all
possible input values
switch(vehicle) {
^
same issue with a switch expression.
regards,
Rémi