Contents Prev Next Up


3.17 Miscellaneous Object Operations

new

Create new object
 
new = 187
indexbyte1
indexbyte2

Stack: ... => ..., objectref

indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class. The item at that index must be a class name that can be resolved to a class pointer, class. A new instance of that class is then created and a reference to the object is pushed on the stack.

checkcast

Make sure object is of given type
 
checkcast = 192
indexbyte1
indexbyte2

Stack: ..., objectref => ..., objectref

indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class. The string at that index of the constant pool is presumed to be a class name which can be resolved to a class pointer, class. objectref must be a reference to an object.

checkcast determines whether objectref can be cast to be a reference to an object of class class. A null objectref can be cast to any class. Otherwise the referenced object must be an instance of class or one of its superclasses. (See the Java Language Specification for information on how to determine whether a objectref is an instance of a class.) If objectref can be cast to class execution proceeds at the next instruction, and the objectref remains on the stack.

If objectref cannot be cast to class, a ClassCastException is thrown.

Note: Mustn't refer to the Java Language Specification; give semantics here.

instanceof

 
instanceof = 193
indexbyte1
indexbyte2
Determine if an object is of given type

Stack: ..., objectref => ..., result

indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class. The string at that index of the constant pool is presumed to be a class name which can be resolved to a class pointer, class. objectref must be a reference to an object.

instanceof determines whether objectref can be cast to be a reference to an object of the class class. This instruction will overwrite objectref with 1 if objectref is an instance of class or one of its superclasses. (See the Java Language Specification for information on how to determine whether a object reference is an instance of a class.) Otherwise, objectref is overwritten by 0. If objectref is null, it's overwritten by 0.

Note: Mustn't refer to the Java Language Specification; give semantics here.


Contents Prev Next Up