Created
March 23, 2021 14:45
-
-
Save bufferings/144c2439acda936b249f20cc58243a72 to your computer and use it in GitHub Desktop.
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
@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