O'Reilly logo

The Java® Virtual Machine Specification, Java SE 7 Edition, Third Edition by Alex Buckley, Gilad Bracha, Frank Yellin, Tim Lindholm

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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            // ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required