I know how to declare an array of other things, like strings, as follows:
String[] strings = { "one", "two", "tree" };
String[] strings = new String[] { "one", "two", "tree" };
But when it comes to method references, I can't figure out how to avoid to create a list and add each item individually.
Example. Call the method smartListMergeon several different 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 correct way to declare an array of method references?
source
share