- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设以下实际代码结构:
interface I {
I m();
}
abstract class A implements I {
@Override
public abstract A m();
abstract class B extends A {
}
}
为B生成的字节码是
abstract class A$B extends A {
<some stuff>
public I m(); //bridge method
Code:
0: aload_0
1: invokespecial #2 // Method A.m:()LA;
4: areturn
}
注意指向抽象方法A.m()的invokespecial指令的使用。在我看来,根据 invokespecial 上的 JVM 8 规范,这一定会在运行时导致 AbstractMethodError 。 :
If all of the following are true, let C be the direct superclass of the current class.
因此,在我们的示例中,A 将被选为 C。
The actual method to be invoked is selected by the following lookup procedure.
1) If C contains a declaration for an instance method with the same name and descriptor as the resolved method, then it is the method to be invoked.
所以JVM会选择A.m()。
但是运行时异常部分指出:
Otherwise, if step 1, step 2, or step 3 of the lookup procedure selects an abstract method, invokespecial throws an AbstractMethodError.
因此调用该方法将以错误结束。
我只是想知道,为什么Java编译器会生成这样的被判失败的字节码?
附注我猜测上述桥接方法根本不会被调用,因为 A.B 类的最终实现者将覆盖它。但随之而来的问题就出现了:java生成这个桥接方法的目的是为了什么?
最佳答案
我不太明白你想达到什么目的。您想了解为什么会生成该方法吗?
Notice the use of invokespecial instruction pointing to the abstract method A.m(). In my opinion this must lead to an AbstractMethodError at runtime
理论上不应该存在抽象类的实例,任何实例化的子类都必须实现所有抽象方法。所以invokespecial指向实现子类。尝试实例化抽象类通常会被编译器捕获。
当没有找到实现子类时会抛出AbstractMethodError,大多数情况下,当按预期加载不同的类版本或使用字节码操作时,会发生这种情况。
关于javac 生成一个桥接方法,其中包含指向抽象方法的 invokespecial 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42566298/
我有一个在 Silverlight 中开发的应用程序,它必须连接到另一个我无法控制的遗留应用程序,它需要 3005 端口上的 TCP 连接。 我无法修改旧版应用程序以将端口置于 silverlight
我主要使用 Git 工作,并且在 github 上有很多代码。我也想把它放在 Bitbucket 上,供使用 mercurial 的人使用,但更重要的是,因为我也想在我的 domian 上拥有代码,而
有一个emacs插件可以在emacs中直接编辑confluence页面: http://code.google.com/p/confluence-el/ VIM 有类似的东西吗?我无法找到一些东西。
我已在项目中添加了桥接 header ,但随后我也收到“ProjectName\ProjectName - Bridging-Header.h”文件不存在的错误。 最佳答案 在build设置中,为桥接
我有带 libvirt/kvm 虚拟化的 Linux 主机,虚拟机需要“真实的”静态 IP 地址,所以我决定设置桥接网络。我在主机和虚拟机属性中创建了 br0,我设置了源设备:主机设备 vnet0(B
我正在尝试实现以下模型:我有一个包含一些记录(就像可编辑枚举)的字典表(ProductOffer 表)。另外,我有一个主表 (ChangeNet),它应该存储 ProductOffer 的集合。字典不
我有一个理论,但我不知道如何验证它。我们有一个相当大的 iOS 项目,包含大约 200 个 Swift 文件和 240 个 obj-C 文件(以及等量的头文件)。我们仍在使用 Swift 1.2,这意
简而言之,我正在开发一个嵌入式系统,除其他外,它需要一个从 USB 主机端口到设备端口的桥(这只是第一步,稍后传输的信息将被过滤和更改) . 考虑到这基本上是一个 USB 窥探器/嗅探器,我认为应该有
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码): https://github.com/zq2599/blog_demos 关于《Strimzi K
网上搜出来的比较乱,讲的不明不白,因此根据自己弄过一次,确认可行的方式,做个备份,方便日后查阅。 环境: 在oracle vm virtualbox中安装的ubuntu,具体版本名是:ubunt
Symfony 的 bundle、vendor 和 bridge 是什么意思? 最佳答案 小贩 一般来说,vendor是项目的依赖项(又名第三方库)。在 Symfony2 中也是同样的意思。 捆 来自
我正在尝试发布发送到 NSB 主机的 WCF 服务。我查看了 NSB 示例中的 WebServiceBridge 示例,但无法弄清楚如何在 WCF 对应项中使用 NServiceBus.WcfServ
我目前正在尝试将 Google Cloud Messaging 库实现到我的 IOS 应用程序中。我按照说明 from here. 进行操作 但是我遇到了桥接头问题。 This is how my p
我正在快速构建一个 Firebase 应用程序,我正确安装了 cocoa pod,然后创建了一个 Objective-C 文件,这样它就可以使我成为一个桥接 header 。当我尝试在应用程序的其他地
我添加到我的项目桥接头文件中,这样我就可以在 swift 中使用 opencv。我决定我不需要 opencv 所以我删除了桥接头文件,在我这样做之后我无法运行我的项目因为这个错误: :0: 错误:打开
我正在使用 Xcode 8.0,我已经手动创建了 Swift Bridging Header。但是我在 Swift Compiler – Code Generation 下找不到选项 Ojective
我有一个 iphone 应用程序,可以通过以 packages 的形式下载额外的内容来丰富它。 此附加内容(包)是使用 MAC OS 应用程序构建的。 MAC OS 应用程序用于收集资源和艺术品、进行
virtualbox中有四种网络连接方式: nat bridged adapter internal host-only adapter vmware中有三种,其实它跟
网上搜出来的比较乱,讲的不明不白,因此根据自己弄过一次,确认可行的方式,做个备份,方便日后查阅。 环境: 在oracle vm virtualbox中安装的ubuntu,具体版本名是:ubuntu
我正在使用 PHP/Java 桥接您可以找到的获取资本 API here .但是在使用 PHP/Java bridge 连接后(它连接正确并且我测试过),我正在尝试通过为此创建一个对象来使用 API,
我是一名优秀的程序员,十分优秀!