I am working on the site Codingbat, specifically this method in AP-1
public String[] wordsWithout(String[] words, String target) {
ArrayList<String> al = new ArrayList<>(Arrays.asList(words));
al.removeIf(s -> s.equals(target));
return al.toArray(new String[al.size()]);
}
This implementation works, and its what is currently submitted, but when I change the return statement to
return al.toArray(String[]::new);
which should work as far as I know, gives the following error:
no suitable method found for toArray((size)->ne[...]size])
method java.util.Collection.<T>toArray(T[]) is not applicable
(cannot infer type-variable(s) T
(argument mismatch; Array is not a functional interface))
method java.util.List.<T>toArray(T[]) is not applicable
(cannot infer type-variable(s) T
(argument mismatch; Array is not a functional interface))
method java.util.AbstractCollection.<T>toArray(T[]) is not applicable
(cannot infer type-variable(s) T
(argument mismatch; Array is not a functional interface))
method java.util.ArrayList.<T>toArray(T[]) is not applicable
(cannot infer type-variable(s) T
(argument mismatch; Array is not a functional interface)) line:4
Would anyone be so kind as to explain why this doesn't work?