I know how to declare an array of other things, like strings, in this way:
String[] strings = { "one", "two", "tree" };
// or
String[] strings = new String[] { "one", "two", "tree" };
But when it comes to method references, I can't figure out how to avoid having to create a list and add every item individually.
Example: Call the method smartListMerge
on several diferent
matching lists from two sources:
List<Function<TodoUser, TodoList>> listGetters = new ArrayList<>(3);
listGetters.add(TodoUser::getPendingList);
listGetters.add(TodoUser::getCompletedList);
listGetters.add(TodoUser::getWishList);
TodoUser userA = ..., userB = ...;
for (Function<TodoAppUser, TodoList> listSupplier : listGetters) {
TodoList sourceList = listSupplier.apply(userA);
TodoList destinationList = listSupplier.apply(userB);
smartListMerge(sourceList, destinationList);
}
What is the right way to declare an array of method references?