调用Lists.transform
后,我们得到一个TransformingRandomAccessList
。这很棒,只是在尝试打包它时,我们遇到了异常崩溃:
Caused by: org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class for com.google.common.collect.Lists$TransformingRandomAccessList, verify that your class is configured properly and that the Parcelable class com.google.common.collect.Lists$TransformingRandomAccessList$$Parcelable is generated by Parceler.
List<Foo> items = List.transform(...);
Bundle bundle = new Bundle();
bundle.putParcelable("MyItemsKey", Parcels.wrap(items));
任何快速且容易地将项目
转换为普通列表的方法。或者是否有更好的方法将其放入 Bundle
中?
最佳答案
我会用这个:
ImmutableList.copyOf(items);
另一种选择是使用 java 库中的
new ArrayList<Foo>(items);
关于java - 将 `TransformingRandomAccessList<T>` 转换为 `List<T>`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40620151/