0

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

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

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

我在这里做错了什么?

4

1 回答 1

1

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

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

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

首先检查类型是否为 macthing。

于 2013-11-08T07:01:49.620 回答