首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Parceler -在实现中与工厂注释接口

Parceler -在实现中与工厂注释接口
EN

Stack Overflow用户
提问于 2016-05-11 14:50:15
回答 1查看 373关注 0票数 2

在android上使用Parceler时,是否可以使用@Parceler对接口进行注释,并让它在实现类中获取可能的@ParcelConstructor@ParcelFactory注释?

这样做的目的是避免编写自定义ParcelConverter来重用Parceler中的泛型字段映射,但是,像implementations= 论据 to @Parcel这样的东西似乎更多地指向将子类型映射到超级类型(而不是反过来):

代码语言:javascript
复制
@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) {
    ...
  }
}

当然,如果有多个匹配映射,可能会出现歧义,但我似乎找不到任何关于使该功能工作的文档,即使没有任何歧义。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-13 04:08:20

您是正确的,Parceler只对直接带@Parcel注解的类进行操作,而implementations参数(该参数现在已折旧,不久将从api中删除)将用于其他方面。

我将更新这个答案,如果您给出一个具体的例子,说明您希望围绕“泛型字段映射”解决哪些问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37166218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档