Java Type Erasure Problem

前端 未结 5 2097
一个人的身影
一个人的身影 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 03:52

    Sorry, the bad news is that you cannot do this:

    public class Algorithm> {
        public void compute(Set objects) {
        }
    
        public void compute(Set> pairs) {
        }
    }
    

    Due to erasure, both will erase to the same signature. There is no way around this short of renaming one of the methods.

提交回复
热议问题