Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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