invoke-super <interface method> vs invoke-interface <interface method>?
invoke-super <interface method> vs invoke-interface <interface method>?
在 Dex 版本 037+ 中,invoke-super mid
和 invoke-interface mid
之间的行为有何不同,其中 mid
是一个 接口 方法?
我引用了 Dalvik 文档 [1] 中的以下内容,但我无法理解它:
In Dex files version 037 or later, if the method_id refers to an
interface method, invoke-super
is used to invoke the most specific,
non-overridden version of that method defined on that interface. The
same method restrictions hold as for invoke-virtual. In Dex files
prior to version 037, having an interface method_id is illegal and
undefined.
invoke-interface
is used to invoke an interface method, that is, on an
object whose concrete class isn't known, using a method_id that refers
to an interface.
[1] https://source.android.com/devices/tech/dalvik/dalvik-bytecode
Dex 版本 37 添加了对默认接口方法的支持。因此,如果您使用类似 Lmy/interface;->someMethod()V
的方式调用 invoke-super,它将搜索接口层次结构以找到提供该接口实现的第一个接口。
所以,为了更完整的例子,假设我们有几个 类。
Lmy/superinterface;
Lmy/interface;
扩展 Lmy/superinterface;
Lmy/superclass;
实现了 Lmy/interface;
Lmy/subclass;
扩展 Lmy/superclass;
假设 Lmy/superinterface;
定义了 someMethod()V
的默认实现,Lmy/superclass;
和 Lmy/subclass;
都提供了自己的实现
如果v0中有Lmy/subclass;
的对象,那么
invoke-super {v0}, Lmy/interface;->someMethod()V
从 Lmy/superinterface;
调用实现
invoke-super {v0}, Lmy/subclass;->someMethod()V
从 Lmy/superclass;
调用实现
invoke-virtual {v0}, Lmy/subclass;->someMethod()V
从 Lmy/subclass;
调用实现
在 Dex 版本 037+ 中,invoke-super mid
和 invoke-interface mid
之间的行为有何不同,其中 mid
是一个 接口 方法?
我引用了 Dalvik 文档 [1] 中的以下内容,但我无法理解它:
In Dex files version 037 or later, if the method_id refers to an interface method,
invoke-super
is used to invoke the most specific, non-overridden version of that method defined on that interface. The same method restrictions hold as for invoke-virtual. In Dex files prior to version 037, having an interface method_id is illegal and undefined.
invoke-interface
is used to invoke an interface method, that is, on an object whose concrete class isn't known, using a method_id that refers to an interface.
[1] https://source.android.com/devices/tech/dalvik/dalvik-bytecode
Dex 版本 37 添加了对默认接口方法的支持。因此,如果您使用类似 Lmy/interface;->someMethod()V
的方式调用 invoke-super,它将搜索接口层次结构以找到提供该接口实现的第一个接口。
所以,为了更完整的例子,假设我们有几个 类。
Lmy/superinterface;
Lmy/interface;
扩展Lmy/superinterface;
Lmy/superclass;
实现了Lmy/interface;
Lmy/subclass;
扩展Lmy/superclass;
假设 Lmy/superinterface;
定义了 someMethod()V
的默认实现,Lmy/superclass;
和 Lmy/subclass;
都提供了自己的实现
如果v0中有Lmy/subclass;
的对象,那么
invoke-super {v0}, Lmy/interface;->someMethod()V
从Lmy/superinterface;
调用实现
invoke-super {v0}, Lmy/subclass;->someMethod()V
从Lmy/superclass;
调用实现
invoke-virtual {v0}, Lmy/subclass;->someMethod()V
从Lmy/subclass;
调用实现