Skip to content

Instantly share code, notes, and snippets.

@karl82
Created June 4, 2016 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karl82/2e2013654946489b1e43e9cefe01d52c to your computer and use it in GitHub Desktop.
Save karl82/2e2013654946489b1e43e9cefe01d52c to your computer and use it in GitHub Desktop.
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
Copy link
Author

karl82 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