在android上使用Parceler时,是否可以使用@Parceler对接口进行注释,并让它在实现类中获取可能的@ParcelConstructor和@ParcelFactory注释?
这样做的目的是避免编写自定义ParcelConverter来重用Parceler中的泛型字段映射,但是,像implementations= 论据 to @Parcel这样的东西似乎更多地指向将子类型映射到超级类型(而不是反过来):
@Parcel // can this be used to serialize **all** implementations ...
public interface MyIface {
String getProperty1();
int getProperty2();
}
public class MyImpl implements MyIface {
@ParcelFactory // and can this be used to deserialize the interface?
public static MyImpl fromParcelerValues(final String property1, final int property2) {
...
}
}当然,如果有多个匹配映射,可能会出现歧义,但我似乎找不到任何关于使该功能工作的文档,即使没有任何歧义。
发布于 2016-05-13 04:08:20
您是正确的,Parceler只对直接带@Parcel注解的类进行操作,而implementations参数(该参数现在已折旧,不久将从api中删除)将用于其他方面。
我将更新这个答案,如果您给出一个具体的例子,说明您希望围绕“泛型字段映射”解决哪些问题。
https://stackoverflow.com/questions/37166218
复制相似问题