我想创建一个使用另一个方法作为参数的方法。但是我该怎么做呢?我应该如何修改才能正确? (例如)
class Illustration
{
public boolean condition1 (int a, double b)
{
return (a <= b)
}
public boolean condition2 (int a, double b)
{
return (a > b)
}
public double operation (int a, double b, Method cond)
{
if (cond(a, b))
{
return (a + b)
} else {
return (a - b)
}
}
}
与其尝试将一个方法错误地传递为另一个方法的参数,不如使用它,
You can use
java.util.function.BiPredicate
for this one:并传递lambda: