3 Replies Latest reply on May 2, 2010 9:44 PM by 843793

    generic method vs wildcarded parameter?

      In the following, 'doesntCompile' doesn't compile. As you can see, it uses a wildcard in it's parameter. The method 'alsoCompiles' compiles, but uses a type variable in it's parameter. Various books I've read discuss that type variables (in generic methods) are needed to resolve issues between multiple parameters, or between a parameter and the method's return type. But in this case, there is only one parameter and the return type is void. So I don't understand why 'doesntCompile' won't compile. I'd appreciate it if someone could clarify this issue. Thanks in advance...
      import java.util.Iterator;
      public class Test {
           class Bar<E> {}
           public void m() {
                compiles((Iterator<Bar<String>>) null);
                alsoCompiles((Iterator<Bar<String>>) null);
                doesntCompile((Iterator<Bar<String>>) null);
           public void compiles(Iterator<?> x) {}
           public <T> void alsoCompiles(Iterator<Bar<T>> x) {}     
           public void doesntCompile(Iterator<Bar<?>> x) {}