I'm trying to crate my own thread safe event handling but I get E cannot be resolved to a type
error on class decleration line below. How can I fix this?
Observers.java
public final class Observers<T extends EventHandler<E>> {
private CopyOnWriteArrayList<T> mListeners = new CopyOnWriteArrayList<T>();
public interface EventHandler<E> {
public void HandleEvent(Object sender, E e);
}
/*...*/
public void dispatchEvent(Object sender, E args) {
/*...*/
}
}
EventHandler.java
public interface EventHandler<E extends EventArgs> {
/* ... */
}
You've only actually declared a single type parameter in Observers
. Try this:
public final class Observers<E extends EventArgs, T extends EventHandler<E>> {
Note that it looks highly odd for your Observers
class to declare its own nested EventHandler
interface while implementing the outer one - if you really need both of those, I would suggest you rename one of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With