Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bufferings/144c2439acda936b249f20cc58243a72 to your computer and use it in GitHub Desktop.
Save bufferings/144c2439acda936b249f20cc58243a72 to your computer and use it in GitHub Desktop.
@Test
void testInstanceof1() {
Object o = "";
if (o instanceof String s) {
assertTrue(s.isEmpty());
return;
}
fail("ここには来ないよ");
}
@Test
void testInstanceof2() {
Object o = "";
if (!(o instanceof String s)) {
throw new AssertionError("ここには来ないよ");
}
// ここでも s が使える
assertTrue(s.isEmpty());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment