gpt4 book ai didi

Java : Using addAll method on Custom list

转载 作者:行者123 更新时间:2023-12-01 13:52:41 26 4
gpt4 key购买 nike

我正在尝试在自定义列表上使用 addAll() 方法。我有以下 Java 代码;

PaginatedResponse<CustomType> paginatedResponse = new PaginatedResponse<CustomType>();
List<PaginatedResponse<CustomType>> paginatedResponseList = new ArrayList<PaginatedResponse<CustomType>>();
paginatedResponseList.addAll(methodReturningPaginatedResponseOfCustomType);

但是我收到错误。没有找到合适的 addAll() 方法

我在这里做错了什么?

最佳答案

如果调用 addAll 方法,那么在您的代码示例中,methodReturningPaginatedResponseOfCustomType 应该是一种集合类型,例如 List< PagulatedResponse< CustomType >> 。

如果methodReturningPaginatedResponseOfCustomType是PaginatedResponse 的类型,那么您需要使用 add而不是addAll。

如果 methodReturningPaginatedResponseOfCustomType 是 CustomType 的类型,则列表中的元素与您要添加的 methodReturningPaginatedResponseOfCustomType 不匹配。

首先检查类型是否匹配。

关于Java : Using addAll method on Custom list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19853152/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com