我遇到了一个问题,我正在尝试实施“两级”铸造。
下面是显示我正在尝试做的简化代码:
public class Array2D<T>
{
private T[][] _array;
....
public T get( int x , int y )
....
public void set( T o , int x , int y )
}
直到那里,没有问题。
我正在尝试扩展此类,例如我可以在 getter 和 setter 中封装 SoftReferences 的使用:
public class Array2DSoftRefs<T> extends Array2D<SoftReference<T>>
{
public T get( int x , int y )
{
return super.get(x,y).get(); // get the array element, then the SoftReference contents
}
....
public void set( T o , int x , int y )
{
super.set( new SoftReference<T>(o) ,x,y); // generate the SoftReference on-the-fly
}
}
事实上,我被踢掉了,因为编译器/语法分析器跳过了泛型擦除,然后@Override
注释无法帮助我(队长明显)。
我不知道如何从模板返回T
类型。SoftReference<T>
我试图放入两个泛型T
和U
for SoftReference<T>
,但没有成功。