Created
January 15, 2021 13:54
-
-
Save gyselph/6f22547a7dbb86801e51882eed9787b3 to your computer and use it in GitHub Desktop.
Java 7 to 15: sealed class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed interface Fruit permits Apple, Pear { | |
String getName(); | |
} | |
public final class Apple implements Fruit { | |
public String getName() { return "Apple"; } | |
} | |
public final class Pear implements Fruit { | |
public String getName() { return "Pear"; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment