【发布时间】:2010-12-12 05:05:36
【问题描述】:
标准Runnable 接口只有非参数化run() 方法。还有Callable<V> 接口与call() 方法返回泛型类型的结果。我需要传递通用参数,如下所示:
interface MyRunnable<E> {
public abstract void run(E reference);
}
为此目的是否有任何标准接口,或者我必须自己声明那个基本接口?
【问题讨论】:
-
如果您在使用 匿名内部
Runnable或Callable<V>时遇到此问题,则您不能也不需要使用参数。请参阅 this question 和 the answer 如何做到这一点。