Java – why does this type parameter remain in bytecode?

Type erasure page says

However, for the following classes:

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

Javap - C foo print:

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

Why is the type parameter not replaced by the binding (charsequence), but saved as e?

Solution

You are not printing bytecode This is the method signature It's there, so the compiler can enforce type safety when compiling other classes that call it

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>