core/src/test/java/com/google/common/truth/SubjectTest.java
public void isInstanceOfSuperclass() {
    assertThat(3).isInstanceOf(Number.class);
void isInstanceOfExactType()
core/src/test/java/com/google/common/truth/SubjectTest.java
if (isGwt()) {
      try {
        assertThat("a").isInstanceOf(CharSequence.class);
        fail();
void isInstanceOfImplementedInterface()
core/src/test/java/com/google/common/truth/SubjectTest.java
public void isInstanceOfUnrelatedInterface() {
    if (isGwt()) {
      try {
        assertThat(4.5).isInstanceOf(CharSequence.class);
        fail();
void isInstanceOfUnrelatedClass()
core/src/test/java/com/google/common/truth/SubjectTest.java
expectFailure.whenTesting().that((Object) null).isInstanceOf(Long.class);
    assertThat(expectFailure.getFailure())
        .hasMessageThat()
        .isEqualTo("Not true that <null> is an instance of <java.lang.Long>");
void isInstanceOfClassForNull()
core/src/test/java/com/google/common/truth/SubjectTest.java
expectFailure.whenTesting().that((Object) null).isInstanceOf(CharSequence.class);
    assertThat(expectFailure.getFailure())
        .hasMessageThat()
        .isEqualTo("Not true that <null> is an instance of <java.lang.CharSequence>");
void isInstanceOfInterfaceForNull()
core/src/test/java/com/google/common/truth/SubjectTest.java
public void isNotInstanceOfUnrelatedInterface() {
    if (isGwt()) {
      try {
        assertThat(5).isNotInstanceOf(CharSequence.class);
        fail();
void isNotInstanceOfUnrelatedClass()
core/src/test/java/com/google/common/truth/SubjectTest.java
expectFailure.whenTesting().that(5).isNotInstanceOf(Integer.class);
    assertThat(expectFailure.getFailure())
        .hasMessageThat()
        .isEqualTo("<5> expected not to be an instance of java.lang.Integer, but was.");
void isNotInstanceOfExactType()
core/src/test/java/com/google/common/truth/SubjectTest.java
@Test
  public void isNotInstanceOfImplementedInterface() {
    if (isGwt()) {
      try {
        assertThat("a").isNotInstanceOf(CharSequence.class);
        fail();
void isNotInstanceOfSuperclass()
Object instance  Class<?> clazz
core/src/main/java/com/google/common/truth/Platform.java
/**
   * Returns true if the instance is assignable to the type Clazz (suitable for a GWT environment).
   */
  static boolean isInstanceOfTypeGWT(Object instance, Class<?> clazz) {
    String className = clazz.getName();
    Set<String> types = new LinkedHashSet<>();
    types.add(instance.getClass().getCanonicalName());
    addTypeNames(instance.getClass(), types);
    return types.contains(className);
boolean isInstanceOfTypeJava(Object instance, Class<?> clazz)
Class<?>[] interfaces  Set<String> types
core/src/main/java/com/google/common/truth/Platform.java
for (Class<?> interfaze : interfaces) {
      types.add(interfaze.getName());
      addInterfaceNames(interfaze.getInterfaces(), types);
void addInterfaceNames(Class<?>[] interfaces, Set<String> types)
Class<?> clazz  Set<String> types
core/src/main/java/com/google/common/truth/Platform.java
for (Class<?> current = clazz; current != null; current = current.getSuperclass()) {
      types.add(current.getName());
      addInterfaceNames(current.getInterfaces(), types);
void addTypeNames(Class<?> clazz, Set<String> types)
though in GWT clazz can only be a
   * concrete class that is an ancestor class of the instance or the direct type of the instance.
   */
  static boolean isInstanceOfTypeGWT
core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java
String className = clazz.getName();
    Set<String> types = new LinkedHashSet<String>();
    addTypeNames(instance.getClass(), types);
    return types.contains(className);
type Clazz (though in GWT clazz can only be a
   * concrete class that is an ancestor class of the instance or the direct type of the instance.
   */
  static boolean isInstanceOfTypeGWT(Object instance, Class<?> clazz)