Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Not sure about C#, but in Java if you write `sealed` correctly you won't need the catch-all throw.

Will the compiler check that you have handled all the cases still? (Genuinely unsure — not a Java programmer)



Yes

https://openjdk.org/jeps/409#Sealed-classes-and-pattern-matc...

> with pattern matching for switch (JEP 406)the compiler can confirm that every permitted subclass of Shape is covered, so no default clause or other total pattern is needed. The compiler will, moreover, issue an error message if any of the three cases is missing


Yes, that's the whole purpose of marking an interface/class `sealed`.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: