What is the meaning of the rules for Java assembly instruction instanceof?

Viewed 212

When drilling down to the operator instanceof on the Java bytecode assembly instruction level, it corresponds to a Java assembly instruction instanceof. But I read the rules used to

determine whether an objectref that is not null is an instance of the resolved type:

The second rule told:

If S is an interface type, then:

  • If T is a class type, then T must be Object.
  • If T is an interface type, then T must be the same interface as S or a superinterface of S.

This made me confused. Does "S is an interface type" mean the reference type of S is an interface type? if so the first rule "If T is a class type, then T must a Object" can not hold true. For instance,

CharSequence charSequence = new StringBuilder("test");
System.out.println(charSequence instanceof StringBuilder);
System.out.println(charSequence instanceof String);

the second line in the code above would print true, whereas the third line above would print false. So I doubt my understanding is probably wrong, anyone can help to explain the meaning of the rule above?

1 Answers
Related