Please take a look at the code snippet below:
interface IFoo<E>{
void doFoo(E env);
}
class A<E>{
public void doA(E env){}
}
public class Foo<E> implements IFoo<E>{
public A<E> a;
@Override
public void doFoo(E env) {
a.doA(env);
}
private class FooInner<E> implements IFoo<E>{
@Override
public void doFoo(E env) {
a.doA(env);
}
}
}
Eclipse complains inside of private inner class a.doA(env) with the following message.
The method doA(E) in the type A<E> is not applicable for the arguments (E)
It doesn’t seem like accessibility issue because non-static inner class have an access to all instance variables of the outter class. It looks like I defined my generics wrong somewhere. Can anyone explain me what I am doing wrong here?
The type of the enclosing class is part of the type of the inner class.
FooInneris already parameterized byE, because it’s part of the outer class; the explicit parameterization is redundant and incorrect, because it’s actually trying to introduce a new type parameter using the same name as the existing one. Just remove the<E>inprivate class FooInner<E>, and you’re golden.