Suppose I have such an interface
public interface Foo<Ret, Arg> { public Ret doSomething(Arg arg); }
And a specific implementation class that only has package visibility.
class FooImpl<Ret, Arg1, Arg2> implements Foo<Ret, Arg>, Bar<Ret, Arg1, Arg2> {
(An example of how this can happen is the implementation of Foo and Bar in FooImpl forwards methods declared by two interfaces to one varargs method)
Now suppose that there is a static method somewhere in the same package that returns FooImpl as Foo . You might think that you can use return new FooImpl<Ret, Arg1, ?>(...) when you really can't (you should use a specific dummy type like Arg2 , for example, return new FooImpl<Ret, Arg1, Object>(...) , say).
Any idea why this is so, especially since the Foo interface and package visibility effectively hide FooImpl from using the static method? This is due to the fact that to some extent you can use reflection to get to the Bar parts of FooImpl , where you need a specific type?
source share