<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello all!<div><br></div><div>I've played around with the exhaustiveness check and I'd like to</div><div>discuss whether the following code should compile or it is right not to compile.</div><div><br></div><div><div>import java.util.*;</div><div>import java.io.*;</div><div><br></div><div>sealed abstract class MyAbstractException extends RuntimeException {</div><div>    final static class MyException extends MyAbstractException {}</div><div>}</div><div><br></div><div>final class MyUncheckedException extends UncheckedIOException {</div><div>    public MyUncheckedException() {</div><div>        super(null);</div><div>    }</div><div>}</div><div><br></div><div>public class SealedException {</div><div>    public static void main(String[] args) {</div><div>        try {</div><div>            throw new MyUncheckedException();</div><div>        } catch (MyAbstractException | MyUncheckedException e) {</div><div>            switch (e) {</div><div>                case MyAbstractException.MyException a -> {}</div><div>                case MyUncheckedException b -> {}</div><div>            }</div><div>        }</div><div>    }</div><div>}</div></div><div><br></div><div>As MyUncheckedExceptionh is final, and MyAbstractException.MyException is the only implementation available for MyAbstractException, I guess it is exhaustive, but the compiler disagrees.</div><div><br></div><div><div>SealedException.java:23: error: the switch statement does not cover all possible input values</div><div>            switch (e) {</div><div>            ^</div></div></div></div></div></div></div>