如何解决此警告 用 forEach 中的方法引用替换此 lambda
How resolve this warning Replace this lambda with a method reference in forEach
在这段代码中,我有这个警告:
Replace this lambda with a method reference.
attrs.forEach((key, value) -> {
attributes.put(key, value);
}
);
我不知道如何解决这个错误,因为它在 forEach 中,在 map 中,我可以使用 ::
,但在这里,我不能。
有什么想法吗?
Sonar 的意思是:
attrs.forEach(attributes::put);
在这段代码中,我有这个警告:
Replace this lambda with a method reference.
attrs.forEach((key, value) -> {
attributes.put(key, value);
}
);
我不知道如何解决这个错误,因为它在 forEach 中,在 map 中,我可以使用 ::
,但在这里,我不能。
有什么想法吗?
Sonar 的意思是:
attrs.forEach(attributes::put);