Created
December 16, 2021 20:35
-
-
Save agiri23/4f073f0bf266c8d276d448c371109c38 to your computer and use it in GitHub Desktop.
pattern matching switch case with yield
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 static void onShowWithYield(Country country) { | |
String output = switch (country) { | |
case NETHERLANDS, POLAND, GERMANY -> { | |
System.out.println("European Country" + country); | |
yield "Country belongs to Europe Continent"; | |
} | |
case INDIA, BHUTAN, NEPAL -> { | |
System.out.println("Asian Country" + country); | |
yield "Country belongs to Asian Continent"; | |
} | |
default -> "It's from Wakanda"; | |
}; | |
System.out.println(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment