What is the meaning of the >
token in this code copied from www.JavaPractices.com? When I replace it with the more conventional looking
The joker ?
can hold any type. If you want to use the same type for all methods/members you can make the whole class generic. By writing StopAlarmTask<T>
you define the type T
in the whole class.
private final class StopAlarmTask<T> implements Runnable
{
StopAlarmTask(ScheduledFuture<T> aSchedFuture)
{
fSchedFuture = aSchedFuture;
}
public void run()
{ /* */ }
private ScheduledFuture<T> fSchedFuture;
}
Assuming this.executorService
is a subtype of ScheduledExecutorService
(available since Java 1.5), the return type of scheduleWithFixedDelay()
is ScheduledFuture<?>
. You can't change the return type from ScheduledFuture<?>
to ScheduledFuture<T>
, ScheduledFuture<Integer>
or anything else for that matter. You could, however, change it to just ScheduledFuture
since <?>
is a wildcard generic type parameter that approximates a raw type for backward compatibility.
See What is a raw type and why shouldn't we use it? for a good discussion on raw types and generics.