我是java 8的新手并尝试这个。我有一个界面
public interface CurrencyRateDao{
Double getCurrencyRate(String srcCur,String tarCur, int month);
}
以这种方式使用它:
CurrencyRateDao currencyRateDao = new CurrencyRateDaoImpl();
Double rate = ('USD','INR',1) -> currencyRateDao::getCurrencyRate;
给出错误:
此表达式的目标类型必须是功能接口。
请说明上述代码有什么问题
你只需要
Double rate = currencyRateDao.getCurrencyRate("USD", "INR", 1);
如果您将接口表示为lambda,它看起来像:
CurrencyRateDao currencyRateDao = (srcCur, tarCur, month) -> Double.MAX_VALUE;
// accepts three arguments and returns a Double value