我在JDK 1.7中使用Java集合时出错:
我在此行中收到此异常: proposalStatuses.addAll(getAllSubmittedStatuses())
java.lang.UnsupportedOperationException
at java.util.AbstractList.add(Unknown Source)
at java.util.AbstractList.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
试图将集合添加到列表中
/**
* Gets the all submitted statuses.
*
* @return the all submitted statuses
*/
private Collection<ProposalStatus> getAllSubmittedStatuses() {
return Arrays.asList(
ProposalStatus.SAVED_TO_IOS
, ProposalStatus.SENDED_TO_IOS_IN_PROGRESS
);
}
/**
* Gets the all received statuses.
*
* @return the all received statuses
*/
private Collection<ProposalStatus> getAllReceivedStatuses() {
Collection<ProposalStatus> proposalStatuses =
Arrays.asList(
ProposalStatus.RECEIVED_BY_IOS
, ProposalStatus.SUBMITTED_TO_IOS
, ProposalStatus.RECEIVED_IOS
);
proposalStatuses.addAll(getAllSubmittedStatuses());
return proposalStatuses;
}
最佳答案
从javadoc of Arrays.asList()
(重点是我):
简而言之:您无法从此类列表中获取.add*()
或.remove*()
!您将不得不使用另一个可修改的List实现(例如ArrayList
)。