简体   繁体   English

如何将此lambda表达式转换为方法参考

[英]How to convert this lambda expression into method reference

How to convert this lambda expression into method reference. 如何将此lambda表达式转换为方法参考。 Here rs is a ResultSet and rowNum is int . 这里rs是一个ResultSetrowNumint

(rs, rowNum) -> getXYZ(rs,rowNum);

the method reference of (rs, rowNum) -> getXYZ(rs, rowNum) is in fact only this::getXYZ (assuming that method is in the same class and it is not static , otherwise it would be YourClass::getXYZ ). 实际上, (rs, rowNum) -> getXYZ(rs, rowNum)的方法引用仅是this::getXYZ (假设该方法位于同一类中,并且不是static ,否则为YourClass::getXYZ )。

But maybe the following will help to build other BiFunction s: 但是也许以下内容将有助于构建其他BiFunction

BiFunction<ResultSet, Integer, WhateverGetXYZReturnedType> yourMethodReference() {
    return (rs, rowNum) -> getXYZ(rs,rowNum); // or just: this::getXYZ
}

and use it with: 并用于:

...(this::yourMethodReference)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM