什么List<?>意思,它只是意味着一个未指定类型的对象列表?
谷歌搜索字符串<?>返回没有任何用处(:
<?>从www.JavaPractices.com复制的此代码中令牌的含义是什么?当我用更常规的<T>用于泛型类型的替换它时,它无法编译.(错误:T无法解析为某种类型.)为什么?
// <?> occurs 3 times in the entire program. When it is replaced with <T> the
// program no longer compiles.
void activateAlarmThenStop()
{
Runnable myPeriodicTask = new PeriodicTask();
ScheduledFuture<?> soundAlarmFuture =
this.executorService.scheduleWithFixedDelay(myPeriodicTask,
startT,
period,
TimeUnit.SECONDS
);
Runnable stopAlarm = new StopAlarmTask(soundAlarmFuture);
this.executorService.schedule(stopAlarm, stopT, TimeUnit.SECONDS);
}
private final class StopAlarmTask implements Runnable
{
StopAlarmTask(ScheduledFuture<?> aSchedFuture)
{
fSchedFuture = aSchedFuture;
}
public void run()
{
CConsole.pw.println("Stopping alarm.");
fSchedFuture.cancel(doNotInterruptIfRunningFlag);
executorService.shutdown();
}
private ScheduledFuture<?> fSchedFuture;
}
Run Code Online (Sandbox Code Playgroud)
编辑:当然,当我们使用泛型类型的标记时<T>,它必须出现在类声明中.这里没有 …