I'm implementing class
class PairStringList extends ArrayList<String> {
...
@Override
public <T> T[] toArray(T[] a) {
return super.toArray(a);
}
}
I have tests written for this class, and they use such a declaration:
assertArrayEquals(new String[]{}, list.toArray(String[]::new));
I see that they use Lambda as parameter. How can I implement toArray() method to run the test correctly? Now I have the next Build Output:
no suitable method found for toArray(String[]::new) method Java.util.Collection.toArray(T[]) is not applicable (cannot infer type-variable(s) T (argument mismatch; Array is not a functional interface))
Any ideas, how can I solve the problem?
Note: I can't change the code of tests
Thanks to everyone! Issue was solved. The problem was that test were written in Java 11, but I was using Java 8. After update to Java 11 everything builds and compiles
listin the test?class PairStringList extends ArrayList<String> {}passes that test already?