I am new to Java, kinda transition from C# to Java.
java.util.function has a interface defined as
Function which is input to
computeIfAbsent method of
I wanted to define and delegate that function to
map.computeIfAbsent(key, k => new SomeObject())
works but I wanted it with callback where func. But the problem is
Function requires input parameter to be defined. How can I set it to
void or with no argument.
computeIfAbsent will always have an input parameter for the passed
Function - that would be the key.
Therefore, just as you can write:
map.computeIfAbsent(key, k -> new SomeObject());
you can also write (assuming the key of your
Map is a
Function<String,SomeObject> func = k -> new SomeObject(); map.computeIfAbsent(key, func);