Reputation: 7
I am new to java 8 and trying this. i have an interface
public interface CurrencyRateDao{
Double getCurrencyRate(String srcCur,String tarCur, int month);
}
Accessing using it this way :
CurrencyRateDao currencyRateDao = new CurrencyRateDaoImpl();
Double rate = ('USD','INR',1) -> currencyRateDao::getCurrencyRate;
Giving an error:
target type of this expression must be a functional interface.
Please suggest what is wrong with above code
Upvotes: 1
Views: 75
Reputation: 32046
You simply need
Double rate = currencyRateDao.getCurrencyRate("USD", "INR", 1);
If you were to represent the interface as a lambda, it would look like :
CurrencyRateDao currencyRateDao = (srcCur, tarCur, month) -> Double.MAX_VALUE;
// accepts three arguments and returns a Double value
Upvotes: 3