Possible Duplicate:
Java: Instanceof and Genericsजेनेरिक के साथ उदाहरण क्यों काम नहीं करता है?
मैं एक ऐसा फ़ंक्शन लिखने की कोशिश कर रहा हूं जो विशिष्ट प्रकार की सूची में एक सामान्य सूची डाली।
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); '[जावा] जेनेरिक उदाहरण' http://stackoverflow.com/questions/1570073/java-instanceof-and- जेनरिक्स, 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 (आदि) –