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

  • Home
  • SEARCH
  • 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 3605776
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:09:58+00:00 2026-05-18T21:09:58+00:00

Consider the following example: public class Sandbox { public interface Listener<T extends JComponent> {

  • 0

Consider the following example:

public class Sandbox {
    public interface Listener<T extends JComponent> {
        public void onEvent(T event);
    }

    public interface AnotherInterface extends Listener<JPanel>, Listener<JLabel> {
    }
}

This fails with the following error

/media/PQ-WDFILES/programming/Sandbox/src/Sandbox.java:20: Sandbox.Listener cannot be inherited with different arguments: <javax.swing.JPanel> and <javax.swing.JLabel>
        public interface AnotherInterface extends Listener<JPanel>, Listener<JLabel> {
               ^
1 error

Why though? There is no overlap in the generated methods. As a matter of fact, that essentially means

public interface AnotherInterface {
    public void onEvent(JPanel event);
    public void onEvent(JLabel event);
}

No overlap there. So why is it failing?


In case your wondering what I’m doing and have a better solution: I have a bunch of Events and a Listener interface that’s almost exactly like the Listener class above. I’m wanting to create an adapter and an adapter interface, and for that I need to extend all the Listener interfaces with a specific event. Is this possible? Is there a better way to do this?

  • 1 1 Answer
  • 3 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-18T21:09:58+00:00Added an answer on May 18, 2026 at 9:09 pm

    No. You cant.
    It’s because generics are supported only at compiler level. So you can’t do thinks like

    public interface AnotherInterface {
        public void onEvent(List<JPanel> event);
        public void onEvent(List<JLabel> event);
    }
    

    or implements interface with several parameters.

    upd

    I think workaround will be like this:

    public class Sandbox {
    //    ....
        public final class JPanelEventHandler implements Listener<JPanel> {
            AnotherInterface target;
            JPanelEventHandler(AnotherInterface target){this.target = target;}
            public final void onEvent(JPanel event){
                 target.onEvent(event);
            }
        }
    ///same with JLabel
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following example: public interface ITask { void Execute(); } public class LoggingTaskRunner
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following example: template <typename T> class A { public: void f() {
Consider the following example class Foo{ public: Foo(int i):x(i){} int x; }; void bar(Foo
Consider the following code. public interface IFoo { } public class Bar { public
Consider the following snippet: public class ReflectionTest { public static void main(String[] args) {
Consider the following example code: class Foo { }; class Bar : public Foo
Consider the following example: interface IPropertyCollection { public MethodWrapper GetPropertySetterByName(string name); //<<-- I want
Consider the following simple RESTEasy (JAX-RS) service: @Path(/example-service) public interface ExampleService { @Path(/ping) @GET
Consider the following example: Public Class ParentClass Public Sub GenerateReport Dim Col As Collection

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.