You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public interface Animal {...}
public class Cat implements Animal {...}
public class Dog implements Animal {...}
Switching over this requires a default clause:
switch (myAnimal) {
case Dog d -> "dog"
case Cat c -> "cat"
default -> "There is no other class that implements Animal but I still need this clause here"
}
Avoiding default clauses in switch expressions is considered good practice as it allows the compiler to check for omissions.
Is your feature request related to a problem? Please describe.
The current handling of oneOf does not allow switch expressions on the generated type to be exhaustive.
Currently oneOf generates an interface:
generates
Switching over this requires a default clause:
Avoiding default clauses in switch expressions is considered good practice as it allows the compiler to check for omissions.
Describe the solution you'd like
generates
Describe alternatives you've considered
The suggested feature is the canonical way to express sum types in Java, hence the canonical fit for oneOf.
Additional context
The text was updated successfully, but these errors were encountered: