I am having a scenario where I am calling a function present in hashmap value as follows,
Map<Character, IntSupplier> commands = new HashMap<>();
// Populate commands map
int number=10;
commands.put('h', () -> funtion1(number) );
commands.put('t', () -> funtion1(number) );
// Invoke some command
char cmd = 'h';
IntSupplier result= commands.get(cmd); //How can I pass a parameter over here?
System.out.println(" Return value is "+result.getAsInt());
My question is that can I pass the parameter to the function (function1) when getting the hashmap value i.e. when using commands.get(cmd).
Thank you.
function1look like (what is its signature)? Is it anint function1(int i) { ... }?IntFunctioninstead of anIntSupplier.