Skip to content

Instantly share code, notes, and snippets.

@agiri23
Created December 16, 2021 20:35
Show Gist options
  • Save agiri23/4f073f0bf266c8d276d448c371109c38 to your computer and use it in GitHub Desktop.
Save agiri23/4f073f0bf266c8d276d448c371109c38 to your computer and use it in GitHub Desktop.
pattern matching switch case with yield
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