Higher order function in java, how to write a method that take no parameter and return a Map which Map's value is a method i java

jay :

I want a method that takes no parameter, then return a map(a,b) that b is a method that is a list of string

Crummy :

Expanding from @donquih0te's answer, you can use a map of whatever your key is to a Supplier:

Map<Object, Supplier<List<String>>> map = new HashMap<>();
map.put("foo", () -> List.of("bar"));
Supplier<List<String>> = map.get("foo");
List<String> result = supplier.get();
System.out.println(result);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=238116&siteId=1