public class StrangeParamMethod {
static void f(ArrayList<String> list){};
public static void main(String... args){
ArrayList<String> list = new ArrayListGenerator().list(); //assigns without problems
f(new ArrayListGenerator().list()); //compile error
}
}
class ArrayListGenerator {
<K> ArrayList<K> list(){
return new ArrayList<K>();
}
}
Please tell, why do I get compile error at the pointed string, when at the string over no problem occurs. I know how solve that compile error, but I want to know why there is such difference in this particular case.
P.S. I know that compile error solves by f(new ArrayListGenerator().<String>list());