I have code like
public class Functionz {
public static boolean test() {
return true;
}
public static void main(String[] args) {
Function[] funcs = new Function[] {test}; // and others
for (Function func : funcs) {
func();
}
}
}
and my error is: cannot find symbol: test in the line with the function array declaration.
Hope this isn't a stupid question, very new to java, not new to object oriented languages like python and C++.
A
Functionin Java does takes one parameter as input and one as output.You might declare parameter's type this way :
Function<Integer, String>is a function that transforms anIntegerinto aStringYour method
test()does not take any input value and outputs abooleanso it's aSupplier.Your code would compile if test requires one (and only one parameter) like
Here's the list of those types
Please note that
Functiondoesn't type its parameters in construction because you can't create arrays with generic type in Java (you might for specific usecases) => Use aListwill help you here