I am trying to create an array of functions to pass to a method:
private void test(Function<?,?>... fns) {
return;
}
In order to do so, I can create the array, and add objects one by one with:
Function<A, B>[] fnArr = new Function[10];
fnArr[0] = Class1::staticMethod1;
fnArr[1] = Class1::staticMethod2;
fnArr[2] = Class1::staticMethod3;
...
But when I try to to this while initializing array:
Function<A, B>[] fnArr = new Function<A, B>[] { Class1::staticMethod1}
I get following error:
Cannot create a generic array of Function
Why is this? How can I avoid having a lot of lines to initialize the array by adding objects 1 by 1?
Note I need a solution for java8