2

I'm porting an SDK from Android to plain Java and have run into an AutoParcel annotation that I don't understand.

Here's the original class and a snippet below:

@AutoParcel.Builder
public abstract static class Builder {
    public abstract Builder id(String id);
...
    public abstract SimpleFeature build();
}

public static Builder builder() {
    return new AutoParcel_SimpleFeature.Builder();
}

I am able to pretty much port everything to AutoValue without incident, except that last function, as I don't understand what it is or it's equivalent in AutoValue.

Can someone explain what this is, and what its equivalent is in AutoValue?

4

2 回答 2

2

正如 JohnWowUs 的评论所暗示的,这主要是一个 Eclipse 问题。

他提到的链接只是解决方案的一部分,但我不需要将更多的 JAR 放入项目中。借助AutoValue repo 中的问题并专门配置 maven-compiler-plugin,将 JDK1.7 设置为目标,并将以下部分添加到 pom.xml:

<annotationProcessors>
    <annotationProcessor>com.google.auto.value.processor.AutoValueProcessor</annotationProcessor>
</annotationProcessors>
于 2016-03-17T18:43:27.787 回答
2

构建注释允许您使用构建器模式构建不可变的 POJO,例如

SimpleFeature.builder().id("test").build()

等效注释(毫不奇怪,因为 AutoParcel 是具有 android 特定功能的 Autovalue 端口,即 Parcelable)

@AutoValue.Builder

您应该能够在https://github.com/google/auto/tree/master/value#builders找到更全面的文档

于 2016-03-16T22:39:24.890 回答