将"转换随机访问列表<T>"转换为"列表<T>"



调用Lists.transform后,得到TransformingRandomAccessList。这是伟大的,除了当试图包它,我们得到一个异常崩溃:

由:org. Parceler. parcelererruntimeexception: Unable to find generated Parcelable class for com.google.common. collectlists $ transformmingrandomaccesslist,请检查你的类是否配置正确,并且Parcelable类com.google.common. collectlists $ transformmingrandomaccesslist $$Parcelable是由Parceler生成的。

List<Foo> items = List.transform(...);
Bundle bundle = new Bundle();
bundle.putParcelable("MyItemsKey", Parcels.wrap(items));

任何快速和容易地将items转换为正常列表。或者是否有更好的方法将其放入Bundle中?

我会这样写:

ImmutableList.copyOf(items);

另一种选择是使用java库中的

new ArrayList<Foo>(items);

最新更新