I know the Function class can be passed as a parameter to another function, like this:
void doSomething(Function f) {
f(123);
}
But is there a way to constrain the arguments and the return type of the function parameter?
For instance, in this case f
is being invoked directly on an integer, but what if it was a function accepting a different type?
I tried passing it as a Function<Integer>
, but Function is not a parametric type.
Is there any other way to specify the signature of the function being passed as a parameter?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…