3.7. Invoking Methods

The normal method invocation for a instance method dispatches on the run-time type of the object. (They are virtual, in C++ terms.) Such an invocation is implemented using the invokevirtual instruction, which takes as its argument an index to a run-time constant pool entry giving the internal form of the binary name of the class type of the object, the name of the method to invoke, and that method’s descriptor (§4.3.3). To invoke the addTwo method, defined earlier as an instance method, we might write:

int add12and13() {     return addTwo(12, 13); }

This compiles to:

Method int add12and13() 0   aload_0              // Push local variable 0 (this) 1   bipush 12            // Push int constant 12 3   bipush 13            // ...

Get The Java® Virtual Machine Specification, Java SE 7 Edition, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.