How does the JLS specify that wildcards cannot be formally used within methods?
I've always been wondering about some weird aspect of Java generics and the use of wildcards. Let's say, I have the following API: public interface X<E> { E get(); E set(E e); } And then, let's say we declare the following methods: public class Foo { public void foo(X<?> x) { // This does not compile: x.set(x.get()); } public <T> void bar(X<T> x) { // This compiles: x.set(x.get()); } } From my "intuitive" understanding, X<?> is in fact the same as X<T> , except that the unknown <T> is formally unknown to client code. But inside of foo() , I would guess that the compiler could infer (pseudo JLS