Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:51:19+00:00 2026-05-26T21:51:19+00:00

EventHandler.java: public abstract class EventHandler<E extends EventArgs> { public abstract void HandleEvent(Object sender, E

  • 0

EventHandler.java:

public abstract class EventHandler<E extends EventArgs> { 
    public abstract void HandleEvent(Object sender, E e);
}

Observers.java:

public class Observers<E extends EventArgs> {

    private CopyOnWriteArrayList<EventHandler<? extends E>> mListeners = new CopyOnWriteArrayList<EventHandler<? extends E>>();

    public void dispatchEvent(Object sender, E args) {
        if (mListeners != null) {
            for (EventHandler<? extends E> listener : mListeners) {
                listener.HandleEvent(sender, args);
            }
        }
    }
}

The following line:

listener.HandleEvent(sender, args);

Causes:

The method HandleEvent(Object, capture#3-of ? extends E) in the type
EventHandler is not applicable for the
arguments (Object, E)

Does anybody how to fix this?

EDIT1
The reason ? super E doesn’t work for me is that I have the following method inside Observers class:

public void addListener(EventHandler<? super E> listener) {
mListeners.add(listener);
}

And that causes:

The method add(EventHandler) in the type
CopyOnWriteArrayList> is not applicable for the
arguments (EventHandler)

EDIT2

The reason the change from ? super E to E doesn’t work for me because of this:
X is not applicable for the arguments Y, when X extends Y

It was already like that but that didn’t work neither 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:51:19+00:00Added an answer on May 26, 2026 at 9:51 pm

    Why are you declaring mListeners to be ~ ? extends E rather than just E?

    If you use

    private CopyOnWriteArrayList<EventHandler<E>> mListeners = new CopyOnWriteArrayList<EventHandler<E>>();
    

    It’ll work.

    Or adopt PECS (Producer Extends, Consumer Super). As others have suggested

    private CopyOnWriteArrayList<EventHandler<? super E>> mListeners = new CopyOnWriteArrayList<EventHandler<? super E>>();
    

    with related changes to the for loop.

    Edit: A fuller example. This shows no warnings or errors, and, based on what you’ve given, would work.

    public static class Sandbox {
        public static interface EventArgs {}
        public static abstract class EventHandler<E extends EventArgs> { 
            public abstract void HandleEvent(Object sender, E e);
        }
        public static class Observers<E extends EventArgs> {
    
            private CopyOnWriteArrayList<EventHandler<? super E>> mListeners
                    = new CopyOnWriteArrayList<EventHandler<? super E>>();
    
            public void dispatchEvent(Object sender, E args) {
                if (mListeners != null) {
                    for (EventHandler<? super E> listener : mListeners) {
                        listener.HandleEvent(sender, args);
                    }
                }
            }
            public void addListener(EventHandler<? super E> listener) {
                mListeners.add(listener);
            }        
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EventHandler.java: public abstract class EventHandler<E> { public abstract void HandleEvent(Object sender, E e); }
I have some code where the timer EventHandler has this void timer_Tick(object sender, EventArgs
Some code typedef void (*EventHandler) (EventObject* sender, EventArgs* args, void* closure); class Control {
So I have this interface public interface EventHandler<E extends EventObject> { public void handleEvent(E
On the MSDN, I have found following: public event EventHandler<MyEventArgs> SampleEvent; public void DemoEvent(string
Good morning, I got a class DirObserver with a custom event: public EventHandler<FileDetectedEventArgs> NewFileDetected;
If the HTML is like: <a href="javascript:void(0)" id="link">Click Me</a> and I set the eventHandler
I've set an eventhandler to an event like this: frm.FormClosed += (sender, args) =>
The .net EventHandler is limited to Templates that inherits from EventArgs. How is that
I'm battling an error I don't quite understand. I have a class in Java,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.