list.addAll()函数不适用于一个列表,可以成功用于其他列表

我的代码;

List<String> items = ...
ConcurrentMap<String,String> resultsByItem = new ConcurrentHashMap<>();

Future<Void> allWork = CompletableFuture.allOf(
    items.stream()
        .map(item -> someWork(item) // Get a completable future for this item
                     .andThen(result -> resultsByItem.put(item,result)) // Append the result to the map
        ).toArray(CompletableFuture[]::new)
);
allWork.join();
// Your futureMap is completed.

list.addAll()函数不适用于一个列表,可以成功用于其他列表

正如您在断点结果中看到的那样;

Future<List<PostModel>> getautoPost(User user,int count) async { List<PostModel> posts = new List<PostModel>(); //other proces... List<PostModel> fromUserPost = await getPostUsers(user,fromUser); posts.addAll(fromUserPost); List<PostModel> fromGroupPost = await getPostGroups(user,fromGroup); posts.addAll(fromGroupPost); return posts; } fromUserPost返回相同的结果,

但是fromGroupPost功能不适用于addAll()

当我清除断点时,fromUserPost返回相同的posts的大小。

这是什么原因?

zwm454 回答:list.addAll()函数不适用于一个列表,可以成功用于其他列表

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3152412.html

大家都在问