What is the point of invokeinterface?

Viewed 12081

I'm reading this article about how JVM invokes methods, and I think I got most of it. However, I'm still having trouble understanding the need for invokeinterface.

The way I understand it, a class basically has a virtual table of methods and when calling a method with either invokevirtual or invokeinterface this virtual table is consulted.

What is the difference, then, between a method that's defined on an interface and a method defined on a base class? Why the different bytecodes?

The description of the instructions also looks very similar.

The article seems to claim that the method table of an interface can have "different offsets" every time a method is called. What I don't understand is why an interface would have a method table at all, since no object can have the interface as its actual type.

What am I missing?

2 Answers
Related