I made a static class method (hereby called a "function") f
that takes a list of Callable<String>
s:
import java.util.concurrent.*;
import java.util.*;
class A {
static void f(List<Callable<String>> l) {}
static <T> List<T> s(T t) {
LinkedList<T> l = new LinkedList<T>();
l.add(t);
return l;
}
public static void main(String[] _) {
f(s(new Callable<String>() {
public String call() throws Exception {
return "HI";
}
}));
}
}
I made another function s
that wraps a single element in a list, so I can make a list with a single Callable
in it to test f
.
It fails to compile unless i extract the Callable
into a variable. Why?
In eclipse, it gets this error:
The method f(List<Callable<String>>) in the type A is not applicable for the arguments (List<new Callable<String>(){}>)
which is odd. It seems be saying an expression (which yields a value) is a type. Using javac it gets a different error:
A.java:11: error: method f in class A cannot be applied to given types;
f(s(new Callable<String>() {
^
required: List<Callable<String>>
found: List<<anonymous Callable<String>>>
reason: actual argument List<<anonymous Callable<String>>> cannot be converted to List<Callable<String>> by method invocation conversion
1 error