Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 148504

Summary: [1.5][compiler] false ambiguous generics method error report
Product: [Eclipse Project] JDT Reporter: Kenneth Xu <kennethxu>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: CLOSED WORKSFORME QA Contact:
Severity: major    
Priority: P3 CC: kennethxu
Version: 3.1.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Kenneth Xu CLA 2006-06-23 23:18:00 EDT
Eclipse generates false ambiguous method error for code below bug javac doesn't

public class EclipseAmbiguousBug {
	interface IWorker<E> {
		void add(E e);
	}
	interface IPerson<E> {
		void add(E e);
	}
	interface IFather<E> extends IWorker<E>, IPerson<E>{
	}
	
	interface IMother<E> extends IPerson<E> {
		void add(E e);
	}
	
	interface IChild<E> extends IFather<E>, IMother<E> {
	}
	
	static class Child<E> implements IChild<E> {
		public void add(E e) {}
	}
	
	public static void main(String[] args) {
		IChild c = new Child();
		c.add(""); // correct warning
		IChild<String> cg = new Child<String>();
		cg.add(""); // false ambiguous error
	}
}
Comment 1 Kenneth Xu CLA 2006-06-23 23:32:34 EDT
The method add(E o) method in the IMother interface is most likely the trigger of the bug. Althought it is not necessary to declare again, a lot of times it was done for the purpose of generating javadoc. For example, java.util.Set redeclares the add method of java.util.Collection. A more real world example is listed below:

import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;

public class EclipseAmbiguousBug2 {
	interface Addable<E> {
		boolean add(E e);
	}
	interface XCollection<E> extends Collection<E>, Addable<E> {}
	
	interface XSet<E> extends XCollection<E>, Set<E> {}
	
	static class TestXSet<E> extends AbstractSet<E> implements XSet<E> {
		public boolean add(E e) {return false;}
		public Iterator<E> iterator() {return null;}
		public int size() {return 0;}
	}

	public static void main(String[] args) {
		XSet xs = new TestXSet();
		xs.add(""); // correctly generated warning
		XSet<String> xs2 = new TestXSet<String>();
		xs2.add(""); // false ambiguous error message
	}
}
Comment 2 Kent Johnson CLA 2006-06-26 10:21:56 EDT
Kenneth, both cases are fixed in 3.2
Comment 3 Kenneth Xu CLA 2006-06-27 11:58:36 EDT
Kent, thanks for your response. I downloaded 3.2RC7 and yes it works fine.
Comment 4 Kenneth Xu CLA 2006-06-27 11:59:57 EDT
verified works in 3.2RC7, closing the bug.