我是 Java 8 的新手,正在尝试这个。 我有一个界面
public interface CurrencyRateDao{
Double getCurrencyRate(String srcCur,String tarCur, int month);
}
以这种方式访问:
CurrencyRateDao currencyRateDao = new CurrencyRateDaoImpl();
Double rate = ('USD','INR',1) -> currencyRateDao::getCurrencyRate;
报错:
target type of this expression must be a functional interface.
请指出上面的代码有什么问题
最佳答案
你只需要
Double rate = currencyRateDao.getCurrencyRate("USD", "INR", 1);
如果您将接口(interface)表示为 lambda,它看起来像:
CurrencyRateDao currencyRateDao = (srcCur, tarCur, month) -> Double.MAX_VALUE;
// accepts three arguments and returns a Double value
关于java - 功能接口(interface)方法引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54980629/