简体   繁体   English

Java:在自定义列表上使用addAll方法

[英]Java : Using addAll method on Custom list

I am trying to use the addAll() method on custom list. 我正在尝试在自定义列表上使用addAll()方法。 I have the following Java code; 我有以下Java代码;

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

However I am getting an error. 但是我遇到一个错误。 no suitable method found for addAll() 找不到适用于addAll()的方法

What am I doing wrong here ? 我在这里做错了什么?

If addAll method is called, then in your code example, methodReturningPaginatedResponseOfCustomType should be a type of collection type, like List< PaginatedResponse< CustomType > > . 如果调用addAll方法,则在您的代码示例中,methodReturningPaginatedResponseOfCustomType应该是集合类型的类型,例如List <PaginatedResponse <CustomType>>。

If methodReturningPaginatedResponseOfCustomType is a type of PaginatedResponse< CustomType >, then you need to use add rather than addAll. 如果methodReturningPaginatedResponseOfCustomType是PaginatedResponse <CustomType>的类型,则您需要使用add而不是addAll。

If methodReturningPaginatedResponseOfCustomType is a type of CustomType, then the element in list does not match with methodReturningPaginatedResponseOfCustomType that you would like to add. 如果methodReturningPaginatedResponseOfCustomType是CustomType类型,则列表中的元素与您要添加的methodReturningPaginatedResponseOfCustomType不匹配。

Check if the type is macthing first. 检查类型是否为Macthing。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM