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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:54:19+00:00 2026-06-10T21:54:19+00:00

I have an interface in Java 6 that compiles correctly: public interface IMultiMap<K, V>

  • 0

I have an interface in Java 6 that compiles correctly:

public interface IMultiMap<K, V> extends Map<K, Set<V>> {

    public int valueSize();

    public boolean put(K key, V value);

    public void clear(Object key);

    public boolean isEmpty(Object key);
}

But in Java 7, this interface doesn’t compile. I get a compile error on boolean put(K, V) that it has the same erasure as V put(K, V). The full error from the compiler:

error: name clash: put(K#1,V#1) in IMultiMap and put(K#2,V#2) in Map have the same erasure, yet neither overrides the other
    public boolean put(K key, V value);
  where K#1,V#1,K#2,V#2 are type-variables:
    K#1 extends Object declared in interface IMultiMap
    V#1 extends Object declared in interface IMultiMap
    K#2 extends Object declared in interface Map
    V#2 extends Object declared in interface Map

For the record, adding any kind of overriding doesn’t work. I tried explicitly overriding Map.put, but the error still comes up. Changing the return type of my put is moot since this error is blocking that potential error from ever being reached, and if this error were fixed, then the two methods wouldn’t have the same name/parameter signature anyway.

I think I might try some reflection on Java 6 and see what the actual parameter types end up being in Java 6’s compiled bytecode. It’s clear that both Java 7 methods are being erased to put(Object, Object). I’ll post the reflection results here once I do that.

In the meantime, my temporary workaround will be just to rename put to putSingle, but is this new behavior correct? Did some part of the generics specifications change for Java 7 that makes the old Java 6 behavior wrong? Or is this a bug in the Java 7 compiler?

Thanks in advance.

EDIT: I ran the reflection code. Check out my answer below.

  • 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-06-10T21:54:21+00:00Added an answer on June 10, 2026 at 9:54 pm

    I think it’s a bug in 1.6 that was fixed in 1.7. Extract from this page:

    Synopsis: A Class Cannot Define Two Methods with the Same Erased Signature but Two Different Return Types
    Description: A class cannot define two methods with the same erased signature, regardless of whether the return types are the same or not. This follows from the JLS, Java SE 7 Edition, section 8.4.8.3. The JDK 6 compiler allows methods with the same erased signature but different return types; this behavior is incorrect and has been fixed in JDK 7.
    Example:

    class A {
       int m(List<String> ls) { return 0; }
       long m(List<Integer> ls) { return 1; }
    }
    

    This code compiles under JDK 5.0 and JDK 6, and is rejected under JDK 7.

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

Sidebar

Related Questions

I have an Java-Annotation that return a double value: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface DoubleValue
I have a Java project that needs a addon interface. I was thinking about
I am learning Java and just found that the Interface can have fields, which
I have an interface like the following: package example; import java.awt.Point; public interface Thing
I have the following code, partly in Java, partly in Scala: Java: public interface
I'm writing a method that forms part of the public interface of a Java
I have an interface Node that asks for the method: public HashSet getNeighbour(); NodeVariable
So I have this interface public interface EventHandler<E extends EventObject> { public void handleEvent(E
I have read that in Java interfaces can't be instantiated ( in the documentation,
I have been developing an user interface with Java Swing, and I have met

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.