Skip to main content
PreparationZone Logo
PreparationZone
Back to Java

Java · Hard · Pro

Pattern matching for switch — handling null and dominance errors?

JavaJava 21+Senior
Model answerPreview

Pattern matching for switch

Switch can match types and patterns with guards. case null handles null explicitly; the compiler errors on dominance when a broader pattern shadows a narrower one.