1
我有一个类ArraySort用下面的代码使用可比接口
private Comparable<Object> a[];
private int nElems;
public ArraySort(int length)
{
this.a = new Comparable[length];
this.nElems =0;
}
为什么Java的发出警告,在此声明
this.a = new Comparable[length];
它发出如下警告的警告
Type safety: The expression of type Comparable[] needs unchecked conversion to conform to Comparable<Object>[]
我知道它只是一个警告,但我很想知道原因
谢谢
使用泛型类型的数组是个坏主意。 –
你声明一个'Comparable
你有没有想过让这个泛型类?我认为这样会更顺利。 –