【问题标题】:Objectify Set vs List对象化集合与列表
【发布时间】:2015-06-23 09:40:56
【问题描述】:

我能否让 Objectify 返回 Set<> 或者它必须始终是 List<>?如果集合是可能的,那我可以做吗

@Entity
public class A{
  ...
  private Set<Key<B>> myBs; // where B is an entity, of course?

  private SortedSet<Key<D>> myDs;// where D is an entity, of course?
}

【问题讨论】:

    标签: google-app-engine google-cloud-datastore objectify


    【解决方案1】:

    是的,您可以,并且 Objectify 将为具体实施创建“显而易见的”选择。但是如果你自己初始化集合并让Objectify回收它会更好。这样您就可以指定比较器等:

    private SortedSet<Thing> things = new TreeSet<>(new FunkyComparator());
    

    Objectify 将清除并加载集合。

    可以在收藏的副标题下找到更多内容:

    https://github.com/objectify/objectify/wiki/Entities

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 2020-02-24
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多