switch exhaustiveness check not working within deconstruction pattern.

David Alayachew davidalayachew at gmail.com
Sun Nov 13 18:59:03 UTC 2022


I should also add, it spit out 3 as the answer.

public class Main {

    public static sealed interface Activity {}
    public static record Sleeping(int hours) implements Activity {}
    public static record Skiing(String resort) implements Activity {}
    public static record Coding() implements Activity {}

    public static void main(String[] args) {

        record Pair(boolean weekend, Activity activity) {}

        var pair = new Pair(true, new Sleeping(8));

        var msg = switch (pair) {
            case Pair(boolean b, Sleeping s) -> "3";
            case Pair(boolean b, Skiing s)   -> "4";
            case Pair(boolean b, Coding c)   -> "5";
        };

        System.out.println(msg);

    }

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221113/3e14c221/attachment.htm>


More information about the amber-dev mailing list