我的代码如下,但我收到了编译错误
The method isInstance(MyClass) is undefined for the type Class<T>
The method cast(MyClass) is undefined for the type Class<T>
代码:
public <T extends MyClass> Collection<T> myMethodName(
Class<T> theClass) {
Set<T> result = Sets.newHashSet();
for (MyClass myObject : myObjects) {
if ( theClass.isInstance(myObject)) {
result.add(theClass.cast(myObject));
}
}
return result;
}