1

Possible Duplicate:
Why are interface method invocations slower than concrete invocations?

Interface are slower than abstract class due to extra indirection.

Kindly explain me the detailed meaning of extra indirection.

Community
  • 1
  • 1
Sunny Gupta
  • 6,929
  • 15
  • 52
  • 80
  • 4
    where is the quote from? – Bozho May 20 '12 at 18:26
  • The statement is false. If you replace an interface with an abstract class, all you have done to the compiled .class file is change one bit flag that marks the type as an interface. Indirection is exactly the same. – Marko Topolnik May 20 '12 at 18:33
  • 2
    @MarkoTopolnik: In the JVM implementations i am aware of, the indirection is *not* the same. Invocations of abstract methods on abstract classes uses a vtable, which is simple and fast; invocations of methods on interfaces use some other mechanism, which is more complex and typically slower. – Tom Anderson May 20 '12 at 20:41
  • @TomAnderson Interesting and nice to know. Now that you say it, it makes sense since an abstract class is part of a single hierarchy, as opposed to interfaces. What I said about the .class file is still true, but the difference in indirection happens at an even lower implementation level. Keep in mind, though, that due to [inline caching](http://stackoverflow.com/a/4424078/1103872) there is no single level of indirection that can be defined, so in reality the difference does indeed fade. – Marko Topolnik May 21 '12 at 07:47

0 Answers0