Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
null instanceof Anything is always false
import org.testng.annotations.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
public class InstanceOfTest {
@Test
public void testNullInstanceOf() throws Exception {
assertThat(null, is(not(instanceOf(Object.class))));
if (!(null instanceof Object)) {
System.out.println("null is never instanceof " + Object.class);
}
}
}
@karl82

This comment has been minimized.

Copy link
Owner Author

commented Jun 4, 2016

And the results is:

instanceof_test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.