Class.isInstance和Class.cast的编译错误

时间:2012-12-07 06:25:03

标签: java class compilation

我的代码如下,但我收到了编译错误

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;
  }

0 个答案:

没有答案