2

I have some test code, which is a ConcreteClass inheriting the AbstractClassForInterface1. In the generated smali code for the constructor of ConcreteClass:

# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 4
    invoke-direct {p0}, Lorg/ucomb/AbstractClassForInterface1;-><init>()V 

    return-void
.end method

p0 is actually the instantiated object of type ConcreteClass, since it's from the instantiation:

new-instance v0, Lorg/ucomb/ConcreteClass1;

invoke-direct {v0}, Lorg/ucomb/ConcreteClass1;-><init>()V

and it is easy to understand that the object v0 has the method Lorg/ucomb/ConcreteClass1;-><init>()V,

Then in the body, why using invoke-direct on the p0 to invoke the super class's constructor like this:

invoke-direct {p0}, Lorg/ucomb/AbstractClassForInterface1;-><init>()V ?

Isn't the invoke-direct supposed to invoke method without virtual method resolution?

monica
  • 1,035
  • 1
  • 9
  • 21

1 Answers1

2

When calling a direct method, the exact method that is being called is specified. In this case, Lorg/ucomb/AbstractClassForInterface1;-><init>()V. This is not a virtual table lookup - it is guaranteed to be the AbstractClassForInterface1 constructor. If it were a virtual table lookup, it would resolve to the most specialized override of the <init>()V method, which would be the <init>()V method in your ConcreteClass1 class.

JesusFreke
  • 19,784
  • 5
  • 65
  • 68
  • So you mean, * syntactically * from the method path in `invoke-direct` instruction, like `invoke-direct {p0}, Lorg/ucomb/AbstractClassForInterface1;->()V`, we will know that the class of the invoked object should be `Lorg/ucomb/AbstractClassForInterface1`, and there is the `` method define in the class? – monica Jan 10 '13 at 07:57
  • I don't think I understand your question. – JesusFreke Jan 11 '13 at 06:38