「2レベル」のキャストを実装しようとしている問題が発生しています。
以下は、私がやろうとしていることを示す単純化されたコードです:
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
2 つのジェネリックとU
forを入れようとしましたSoftReference<T>
が、成功しませんでした。