Skip to content

Instantly share code, notes, and snippets.

@agiri23
Last active December 16, 2021 21:25
Show Gist options
  • Save agiri23/178dc649f408cffe0378cabaf3e6083d to your computer and use it in GitHub Desktop.
Save agiri23/178dc649f408cffe0378cabaf3e6083d to your computer and use it in GitHub Desktop.
pattern matching instanceOf scope
private static void patternMatchingInstanceOfScope() {
Object o = new CountryData("Netherlands","Amsterdam","Europe");
if (o instanceof CountryData countryData && countryData.continent().equals("Europe")) {
System.out.println("This continent of Netherlands is " + countryData.continent());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment