java stream distinct不能传参,用TreeSet或toMap方案写在stream后面又臭又长
又不想用参考1的写Predicate方法给filter做去重,不像是filter字面意思该做的事,虽然硬理解也通
单独写一个工具方法用于处理此问题
调用方法 distinctByKey(list, anyDTO::getIdCard);

    public static   <T, U extends Comparable<? super U>> List<T> distinctByKey(List<T> list, Function<? super T,? extends U>  keyExtractor) {
        if(CollectionUtil.isEmpty(list)) return list;
        //var result = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<T>(Comparator.comparing(keyExtractor))), ArrayList::new));
        //toMap方案,保持原列表顺序,并返回可变list,便于处理
        return list.stream().collect(Collectors.toMap(keyExtractor, Function.identity(), (existing, replacement) -> existing,LinkedHashMap::new))
                .values().st ream().collect(Collectors.toList());
    }