I'm learning java from javascript background, and I wonder is it possible to write similar function in Java. Here is an example in javascript:
function getBalance(side, date) {
let balance;
let getPrice = (f) => {
while ((result = f(date)) == 0) {
date++;
}
return result;
}
if (side) {
let price = getPrice(getPrice1);
// Some calculations
return balance;
} else {
let price = getPrice(getPrice2);
// Some calculations
return balance;
}
}
Where getPrice1 and getPrice2 are previously defined functions. Use of calbacks here helps to keep code short. Im not sure is it possible in Java to pass function as argument without declaring additional interfaces.
I asked this question because it is a simplified example of a real task that I encountered. What do you think will be the most elegant solution?
P.S. Looks like Functional Interfaces is the way here.