我有一些代码如下(摘录):
public interface Event<S> {
S getSource();
}
public interface Subscriber<E> {
void update(E event);
}
public interface EventPublisher<S, E extends Event<S>> {
void addSubscription(S source, Subscriber<E> subscriber);
void removeSubscription(S source, Subscriber<E> subscriber);
}
public class SubscriptionManager<S, E extends Event<S>> implements Subscriber<E>, EventPublisher<S, E> {
...
}
public class MyEvent implements Event<MyEventSource> {
...
}
这一切都很好,但是,我的问题是当我尝试这样的事情时:
public class MyEventHandler {
private final SubscriptionManager<Class<? extends Event<?>>, ? extends Event<?>> subscriptionManager = new SubscriptionManager<>();
Subscriber<? extends Event<?>> subscriber = ...;
subscriptionManager.addSubscription(MyEvent.class, subscriber); **// Compile error**
}
我收到以下错误:
The method addSubscription(Class<? extends Event<?>>, Subscriber<capture#3-of ? extends Event<?>>) in the type SubscriptionManager<Class<? extends Event<?>>,capture#3-of ? extends Event<?>> is not applicable for the arguments (Class<MyEvent>, Subscriber<capture#5-of ? extends Event<?>>)
谁能告诉我怎么了?
谢谢