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 6605245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:15:40+00:00 2026-05-25T19:15:40+00:00

Given the following class, which overrides the getListeners method from AbstractListModel: import java.util.EventListener; import

  • 0

Given the following class, which overrides the getListeners method from AbstractListModel:

import java.util.EventListener;
import javax.swing.AbstractListModel;

public class GenericBug extends AbstractListModel {

/**
 * This is the method of interest
     * This is the exact same method signature that is present in the base class
 */
@Override
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
    // do something useful here...
    return super.getListeners(listenerType);
}

// Not important here
@Override
public int getSize() {
    return 0;
}
@Override
public Object getElementAt(int index) {
    return null;
}
}

This class compiles fine using an Oracle 1.6 JDK. Trying the exact same class using an Oracle 1.7 JDK, I get compile errors saying there is a name clash, but the method isn’t overridden (but it is!!)

Here is the error I get when I use JDK7:

% /usr/java/jdk1.7.0/bin/javac GenericBug.java
GenericBug.java:10: error: name clash: <T#1>getListeners(Class<T#1>) in GenericBug and <T#2>getListeners(Class<T#2>) in AbstractListModel have the same erasure, yet neither overrides the other
        public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
                                             ^
  where T#1,T#2 are type-variables:
    T#1 extends EventListener declared in method <T#1>getListeners(Class<T#1>)
    T#2 extends EventListener declared in method <T#2>getListeners(Class<T#2>)
GenericBug.java:12: error: incompatible types
                return super.getListeners(listenerType);
                                         ^
  required: T[]
  found:    EventListener[]
  where T is a type-variable:
    T extends EventListener declared in method <T>getListeners(Class<T>)
GenericBug.java:9: error: method does not override or implement a method from a supertype
        @Override
        ^
Note: GenericBug.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors

Can someone explain to me what is happening? Is this a compiler bug in JDK1.7, or am I missing something?

  • 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-25T19:15:40+00:00Added an answer on May 25, 2026 at 7:15 pm

    First of all, AbstractListModel is generic, you should not inherit it raw. If

    class GenericBug extends AbstractListModel<Something>
    

    the code compiles.

    Now it is inherited raw, so what’s happening? A raw type’s instance methods all undergo erasure too [4.8], so the raw AbstractListModel has a method

    public EventListener[] getListeners(Class listenerType)
    

    The GenericBug.getListeners method in the subclass does not override this method[8.4.8.1].

    This is based on JLS3, which Javac 6 should follow. So it must have been a Javac6 bug.

    It appears that javac 7 has rewritten the type system algorithms, with a much better result.

    JSL3: http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following class, which simply maps an internal functor f to a function
Given the following Java code: public class Test { static private class MyThread extends
Given the following class, what is your opinion on the best way to handle
Given the following class: class TestClass { public void SetValue(int value) { Value =
Given the following class public class Foo { public int FooId { get; set;
given the following class ... public class Category { public string Name {get;set;} public
Given the following class definitions: public class BaseClass { public string SomeProp1 { get;
Given the following class: class A { public List<B> ListB; // etc... } where
Given the following model: class Project(models.Model): project_name = models.CharField(max_length=255) abstract = models.TextField(blank=True, null=True) full_description
This is just an example, but given the following model: class Foo(models.model): bar =

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.