加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 为什么这个类型参数保留在字节码中?

发布时间:2020-05-24 09:50:18 所属栏目:Java 来源:互联网
导读:type erasure page说 Replace all type parameters in generic types with their bounds or Object if the type parameters are unbounded. The produced bytecode, therefore, contains only ordinary classes, inte

type erasure page说

Replace all type parameters in generic types with their bounds or Object if the type parameters are unbounded. The produced bytecode,therefore,contains only ordinary classes,interfaces,and methods.

但是,对于以下类:

public class Foo<E extends CharSequence> {
    public E something;
}

javap -c Foo打印:

public class Foo<E extends java.lang.CharSequence> {
  public E something;
}

为什么type参数没有被绑定(CharSequence)替换,而是保存为E?

解决方法

你打印的不是字节码.这是方法签名.它放在那里,因此编译器可以在编译调用它的其他类时强制执行类型安全.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读