I have an AutoValue
with an Optional
property. The AutoValue
also has a Builder
. Is there a way to use the Builder
to clear the Optional
property? I could not find anything about it in the AutoValue.Builder
documentation. If this is not possible, is there a suggested work around?
Example below:
package com.google.sandbox;
import com.google.auto.value.AutoValue;
import java.util.Optional;
@AutoValue
public abstract static class MainMessage {
public static Builder builder() {
return new AutoValue_MainClass_MainMessage.Builder();
}
public abstract Optional<Integer> val();
public abstract Builder toBuilder();
/** Builder for MainMessage. */
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder setVal(int value);
public abstract Builder clearVal(); // This causes a compiler error.
public abstract MainMessage build();
}
}
Error:
[AutoValueBuilderNoArg] Method without arguments should be a build method returning com.google.sandbox.MainClass.MainMessage, or a getter method with the same name and type as a property method of com.google.sandbox.MainClass.MainMessage, or fooBuilder() where foo() or getFoo() is a property method of com.google.sandbox.MainClass.MainMessage
public abstract Builder clearVal();