This content has been marked as final. Show 3 replies
I should have mentioned, the specific compiler error occurs on line 9 and is:
The method doesntCompile(Iterator<Test.Bar<?>>) in the type Test is not applicable for the arguments (Iterator<Test.Bar<String>>) Test.java
because Iterator<Test.Bar<?>> and Iterator<Test.Bar<String>> are not the same types (obvious answer, i know). your doesntcompile method takes an Iterator which returns a specific type "Test.Bar<?>". "Test.Bar<String>" is not this specific type, so it doesn't compile. if you want to accept an Iterator which returns some non-specific subclass of "Test.Bar", then you need to change the type to "Iterator<? extends Test.Bar<?>>". [This FAQ|http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html] is a great place to sort out all kinds of similar situations.
Thank you for a great explanation!