Java Type Erasure Problem

前端 未结 5 2096
一个人的身影
一个人的身影 2021-02-11 03:11

I\'ve made an example to demonstrate my problem:

Metrical.java

public interface Metrical
{
    double distance(T other);
}
5条回答
  •  你的背包
    2021-02-11 04:12

    No there isn't.

    You have to remember that someone could call your method with just a vanilla Set, in which case which one would be called?

    That's why you can't do it. Just like you can't do:

    interface A {
      void blah(Set set);
      void blah(Set set);
    }
    

    Same problem.

    The type information isn't available at runtime (ie type erasure).

提交回复
热议问题