1、解决
循环partitionList时,需要用Lists.newArrayList(list)包装一下list。
1 2 3 4 5 6 7 8 9
| List<PartInfoSkuResponse> result = Lists.newArrayList(); if (Objects.nonNull(request) && CollectionUtils.isNotEmpty(request.getInfoIds())) { List<List<BigInteger>> partitionList = Lists.partition(request.getInfoIds(), NumberConstants.NINETY_NINE); for (List<BigInteger> list : partitionList) { request.setInfoIds(Lists.newArrayList(list)); result.addAll(partInfoReadFacade.queryPartInfoSkuByInfoIdBatch(request)); } } return result;
|
2、源码
com.google.common.collect.Lists#partition
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| private static class Partition<T> extends AbstractList<List<T>> { final List<T> list; final int size;
Partition(List<T> list, int size) { this.list = list; this.size = size; }
@Override public List<T> get(int index) { checkElementIndex(index, size()); int start = index * size; int end = Math.min(start + size, list.size()); return list.subList(start, end); }
@Override public int size() { return IntMath.divide(list.size(), size, RoundingMode.CEILING); }
@Override public boolean isEmpty() { return list.isEmpty(); } }
|
Partition类中的get方法使用了list.subList(start, end);
3、问题根源
SubList extends AbstractList implements RandomAccess ,并未实现序列化接口。