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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:59:46+00:00 2026-05-28T01:59:46+00:00

import java.util.*; class A extends HashSet<Integer> { public boolean add(Object obj){ //compiler error return

  • 0

import java.util.*;

  class A extends HashSet<Integer> {
       public boolean add(Object obj){  //compiler error
        return true;
       }
    }
    or
   class Abc <T> {
    public void add(T t){}  //compiler error
    public void add(Object i){} //compiler error (can't overload?)
    }

Error:Name clash: The method add(Object) of type test2 has the same erasure as add(E) of type HashSet but does not override it

i do not know what is the concept behind above error can any one suggest where i can study this concept?

  • 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-28T01:59:47+00:00Added an answer on May 28, 2026 at 1:59 am

    The concept at work here is called type erasure. HashSet defines a method add(T), and you define a method add(Object). At a glance one might think this is OK; that your method just overloads add. However, the erasure of T is Object and so the two have the same erased signature.

    Now, that would be fine if your method properly overrode the method from HashSet. But to do so you should be using add(Integer) and not add(Object). You’re not properly overriding the parent method, so instead it is reported as a conflict since a class cannot provide two methods with the same signature.

    Your Abc example follows the same reasoning. The two methods you declared have the same erased signature so they clash.

    Further Reading

    Angelika Langer Generics FAQ

    • When does a method override its supertype’s method?
    • Can a method of a non-generic subtype override a method of a generic supertype?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
import java.util.Scanner; public class Main extends Hashmap{ public static void main(String[] args) { Hashmap
This is my code; import java.util.*; class State extends HashMap<Character, State>{ boolean isFinal; State
package de.tablayoutexample; import java.util.List; import android.os.AsyncTask; import android.util.Log; public class CallWebServiceTask extends AsyncTask<String, String,
import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class LoginServlet extends HttpServlet {
package vaannila; import java.util.ArrayList; import com.opensymphony.xwork2.ActionSupport; public class RegisterAction extends ActionSupport { private String
import java.util.*; import java.io.*; import java.util.regex.*; class ZiggyTest2 extends Thread{ String sa; public ZiggyTest2(String
I have the following code: import java.util.*; public class SellTransaction extends Transaction { private
import java.util.AbstractList; public class ItemSet extends AbstractList { private Item[] arr; private ItemClass itemClass;
Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>

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.