gpt4 book ai didi

java - java中如何将函数传递给方法参数

转载 作者:行者123 更新时间:2023-12-01 07:45:16 24 4
gpt4 key购买 nike

APIResponse res = kpiAPIObject.getALLKPIDefinition(); --> 函数a

boolean 状态 = res.getNodeValues("shortName").contains(kpiName); --> 函数b

public void dynamicWait(function a,function b)
{
long t = System.currentTimeMillis();
while (t > System.currentTimeMillis() - 180000 ) {
res = /* execute function a here */
if(/* execute function b here */) {
break;
} else {
Thread.sleep(30000);
continue;
}
}
}

提前致谢

最佳答案

听起来你可以使用一些 lambda:

Supplier<APIResponse> a = kpiAPIObject::getALLKPIDefinition;
Predicate<APIResponse> b = res -> res.getNodeValues("shortName").contains(kpiName);

然后这样调用它们:

APIResponse res = a.get();
if (b.test(res)) {
break;
}

关于java - java中如何将函数传递给方法参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54140902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com