0
所以我試圖做一個簡單的程序,可以找到一個複雜的使用數量泛型的模塊,並比較兩個模塊:錯誤而比較兩種方法
public class ComplexNumber <T extends Number,U extends Number>
implements Comparable<ComplexNumber<T, U>>
{
private T real;
private U imaginary;
public ComplexNumber(T real, U imaginary)
{
this.real=real;
this.imaginary=imaginary;
}
public T getReal()
{
return real;
}
public int compareTo(ComplexNumber<?, ?> o)
{
return this.modul().compareTo(o.modul());
}
public U getImaginary()
{
return imaginary;
}
public double modul()
{
double c=Math.sqrt(real.doubleValue()*real.doubleValue()+imaginary.doubleValue()*imaginary.doubleValue());
return c;
}
public String toString()
{
return String.format("%.2f+%.2fi", real.doubleValue(), imaginary.doubleValue());
}
}
但是它給了我兩個實時一個錯誤在.compareTo功能說明:
,一個在類的開頭「的基本類型雙不能調用的compareTo(雙)」:「在這一行 多個標記 - 類型ComplexNumber必須實現繼承的抽象方法 Comparable> .compareTo(ComplexNumber) - Typ ËComplexNumber必須實現繼承的抽象方法「
不能這樣做。它說在方法中必須使用通配符。 –
誰說的..? –
在我的assigment它說我需要使用通配符。 –