1

有没有人尝试在同一个班级同时使用 AutoValue 和 ActiveAndroid(或 Ollie)?

现在我正在尝试使用一个名为 ActiveAndroid 的库将数据保存到 sqlite 数据库。该库是通过为每个成员变量添加注释 @Column 来构建的。问题是在同一个类上使用 ActiveAndroid 和 AutoValue。使用 AutoValue,我不打算添加成员变量,因为 apt 会为我创建它们。这给我带来了一个问题,因为我无法将 @Column 注释添加到成员变量,因为它还不存在。所以我想知道有人遇到过这个问题,是否有解决方法。

4

1 回答 1

0

This wouldn't work with AutoValue for the exact reason you point out. ActiveAndroid could update their library to work with standard property setter/getters, but currently the @Column annotation can only be applied to fields, not methods.

There is also the issue of your model objects having to subclass their abstract Model class. This shouldn't cause a problem, but does muddy the implementation quite a bit.

You might want to check out SQLDelight from the nice people as Square. As opposed to the ActiveAndroid style create-sqlite-from-java-objects approach, it takes the reverse create-java-objects-from-sql. It's up to you whether that's a benefit or a drawback, but it works quite nicely and plays well with AutoValue.

于 2016-03-24T21:19:18.820 回答