I have some situation where I want to pass method reference of a method which have more than one arguments in forEach, I'm able to pass using single arg method which is execute(Map page) but I do not know how could I pass execute(Map page, Integer userInstanceId) in forEach, need help.
static List<Map<String,Object>> pages = new ArrayList<>();
static Map<String,Object> pageIdWithPageInstanceId = new HashMap<>();
public static void testMethodReference() {
TestListMapLamda tt = new TestListMapLamda();
Integer userInstanceId = 22;
pages.stream().filter(page -> null != pageIdWithPageInstanceId.get(page.get("PageID"))).forEach( tt::execute);//this calling the single arg action which is execute(Map<String,Object> page) but not execute(Map<String,Object> page, Integer userInstanceId)
}
public void execute(Map<String,Object> page) {
page.put("UserInstanceID", 1111);
}
public void execute(Map<String,Object> page, Integer userInstanceId) {
page.put("UserInstanceID", userInstanceId);
}
I can call execute(Map page, Integer userInstanceId) by following code, but I'd like to have some more compact stile like the one argument method reference .
public static void testMethodReference2() {
TestListMapLamda tt = new TestListMapLamda();
Integer userInstanceId = 22;
pages.stream().filter(page -> null != pageIdWithPageInstanceId.get(page.get("PageID"))).forEach( page -> {
tt.execute(page, userInstanceId);
});
}