Last active
December 23, 2021 14:24
-
-
Save agiri23/2f752c8a6554611c1f79c80c9af6a2f6 to your computer and use it in GitHub Desktop.
Pattern Switch case
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
sealed interface SampleSealed permits ClassOne, ClassTwo, ClassThree { | |
} | |
final class ClassOne implements SampleSealed { | |
} | |
final class ClassTwo implements SampleSealed { | |
} | |
record ClassThree(String name) implements SampleSealed { | |
} | |
static String withSealedClass(SampleSealed sampleSealedClassApp) { | |
return switch (sampleSealedClassApp) { | |
case ClassOne classOne -> "Sample class one"; | |
case ClassTwo classTwo -> "Sample class two"; | |
case ClassThree classThree -> "Sample class three"; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment