Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java ambiguous type for method?

EDIT: This turned out not be a problem with the code at all, but with a bug in the Groovy Eclipse plugin (http://jira.codehaus.org/browse/GRECLIPSE-373)

Eclipse is giving me a weird error message about ambiguous types in a Java program and I really don't understand why. I have an interface that takes a generic parameter indicating what type of data it returns.

public interface InterfaceA<T> {
    T getData();
}

One of the implementations of it looks like this:

public class Impl<T extends AnotherClass> implements InterfaceA<Collection<T>> {
    public Collection<T> getData() {
       // get the data
    }
}

There is also a container for an InterfaceA

public class Container<T extends InterfaceA>
{
    private T a;

    public Container(T a) {
        this.a = a;
    }

    public T getA() {
        return a;
    }
}

Doing this causes the "getData is ambiguous" error.

Container<Impl<AnotherClass>> c = new Container(new Impl<AnotherClass>());
Collection<AnotherClass> coll = c.getA().getData();

I'm stumped on this one.

like image 640
Jeff Storey Avatar asked Sep 12 '26 10:09

Jeff Storey


1 Answers

There appears to be a bug causing this from the groovy plugin. http://jira.codehaus.org/browse/GRECLIPSE-373. It is not a java problem at all. Thanks for the help and my apologies.

like image 182
Jeff Storey Avatar answered Sep 15 '26 01:09

Jeff Storey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!