Java fuzzy type method?

Editor: This is not a code problem at all, but there is an error in the groovy Eclipse Plug-in( http://jira.codehaus.org/browse/GRECLIPSE-373 )

Eclipse gives a strange error message about fuzzy types in Java programs. I really don't understand why I have an interface that accepts a generic parameter indicating the data type it returns

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

One implementation looks like this:

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

Interfacea also has a container

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

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

    public T getA() {
        return a;
    }
}

Doing so will result in a "GetData is ambiguous" error

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

I'm sorry about that

Solution

There seems to be an error causing the groovy plug - in http://jira.codehaus.org/browse/GRECLIPSE-373. This is not a Java problem at all Thank you for your help and apology

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>