void (String[] args) { List<Data> list = Collections.emptyList(); Map<Long, Data> map1 = list.stream().collect(Collectors.toMap(data -> data.date().getTime(), Function.identity())); Map<Long, Data> map2 = safeGet(list, li -> li.stream().collect(Collectors.toMap(data -> data.date().getTime(), Function.identity()))); }