码迷,mamicode.com
首页 > 其他好文 > 详细

invokespecial指令

时间:2014-11-28 18:41:44      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   使用   sp   java   on   

早期的指令是invokenonvirtual,但从JDK 1.0.2开始重命名为invokespecial。为了解决下面的问题:

Component A - version 1

public class GrandParent {
  protected void myMethod() {
    // ...
  }
}
public class Parent extends GrandParent {
}

Component B

public class Child extends Parent {
  protected void myMethod() {
    // ...
    super.myMethod();
  }
}

The compiler would compile the super.myMethod() call in Child to invokespecial GrandParent.myMethod(). Now suppose a new version of Component A is released:

Component A - version 2

public class GrandParent {
  protected void myMethod() {
    // ...
  }
}
public class Parent extends GrandParent {
  protected void myMethod() {
    // ...
    super.myMethod();
  }
}

为了兼容性,通过设置ACC_SUPER标记表示使用新语义。从JDK 1.1 以后所有的编译器都设置ACC_SUPER。

invokespecial比起invokenonvirtual来多了一些限制,只能在三种情况下使用:

  • the instance initialization method,
  • a private method of this
  • a method in a superclass of this。

参考资料

invokespecial指令

标签:blog   http   io   ar   os   使用   sp   java   on   

原文地址:http://my.oschina.net/chunquedong/blog/350069

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!