Possible Duplicate:
Java: Instanceof and GenericsなぜinstanceofがGenericで動作しないのですか?
特定のタイプのリストに汎用リストをキャストする関数を作成しようとしています。
Cannot perform instanceof check against type parameter T. Use instead its erasure Object >instead since further generic type information will be erased at runtime.
任意の明確化や、望ましい結果を得るための方法 -
public <T>List<T> castCollection(List srcList, Class<T> clas){
List<T> list =new ArrayList<T>();
for (Object obj : srcList) {
if(obj instanceof T){
...
}
}
return list;
}
しかし、コンパイルエラーを示すobj instanceof T
以下のコードを探しますか?
ありがとうございます。 :)
..あなたが検索しなかったため(-1)。 try [java] generic instanceof' http://stackoverflow.com/questions/1570073/java-instanceof-and-generics、http://stackoverflow.com/questions/13768049/use-instanceof-in-a-generic-方法、http://stackoverflow.com/questions/8741984/why-t-instanceof-t-is-not-allowed-where-t-is-a-type-parameter-and-t-is-a-varia? lq = 1、http://stackoverflow.com/questions/4397660/generics-and-instanceof-java?rq=1(etc) –