- 论坛徽章:
- 459
|
本帖最后由 2009532140 于 2013-12-16 10:39 编辑
好书!
经常写JAVA 代码,但从来没深入研究~
直接看原文文档吧:
Operation
Determine if object is of given type
Format
instanceof
indexbyte1
indexbyte2
Forms
instanceof = 193 (0xc1)
Operand Stack
..., objectref →
..., result
Description
The objectref, which must be of type reference, is popped from the operand stack. The unsigned indexbyte1 and indexbyte2 are used to construct an index into the run-time constant pool of the current class (§2.6), where the value of the index is (indexbyte1 << | indexbyte2. The run-time constant pool item at the index must be a symbolic reference to a class, array, or interface type.
If objectref is null, the instanceof instruction pushes an int result of 0 as an int on the operand stack.
Otherwise, the named class, array, or interface type is resolved (§5.4.3.1). If objectref is an instance of the resolved class or array or implements the resolved interface, the instanceof instruction pushes an int result of 1 as an int on the operand stack; otherwise, it pushes an int result of 0.
The following rules are used to determine whether an objectref that is not null is an instance of the resolved type: If S is the class of the object referred to by objectref and T is the resolved class, array, or interface type, instanceof determines whether objectref is an instance of T as follows:
If S is an ordinary (nonarray) class, then:
If T is a class type, then S must be the same class as T, or S must be a subclass of T;
If T is an interface type, then S must implement interface T.
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.
If S is a class representing the array type SC[], that is, an array of components of type SC, then:
If T is a class type, then T must be Object.
If T is an interface type, then T must be one of the interfaces implemented by arrays (JLS §4.10.3).
If T is an array type TC[], that is, an array of components of type TC, then one of the following must be true:
TC and SC are the same primitive type.
TC and SC are reference types, and type SC can be cast to TC by these run-time rules.
Linking Exceptions
During resolution of the symbolic reference to the class, array, or interface type, any of the exceptions documented in §5.4.3.1 can be thrown.
【from:http://docs.oracle.com/javase/sp ... jvms-6.5.instanceof】 |
|