Wednesday, 6 August 2008

What is the invokespecial JVM instruction?

invokespecial and invokevirtual are two different beasts - both call instance methods.

invokevirtual will invoke an instance method, with dispatch based on the class of the object reference. If a method can't be found an AbstractMethodError is raised.

invokespecial contains special handling for:
  1. superclass method invocations (actually checks the resolved method's class is a superclass of the current class)
  2. private method invocation
  3. instance initialization invocations ( methods, which are void functions generated from constructors)

No comments:

Blog Archive