Skip to content

Conversation

octylFractal
Copy link
Contributor

I think it is worthwhile to allow Optional for properties that use property builders, so I wrote code to support such an option.

The value is an empty Optional by default, and uses Optional.of(builder.build()) to generate an Optional from the builder.

Ex:

@AutoValue
abstract class Foo {
  @AutoValue.Builder
  interface Builder {
    Nested.Builder nestedBuilder();
  }
  
  abstract Optional<Nested> nested();
}

@AutoValue
abstract class Nested {
  
  static Builder builder() {
    return new AutoValue_Nested.Builder();
  }
  
  @AutoValue.Builder
  interface Builder {
  }
}

@octylFractal
Copy link
Contributor Author

I've added the tests here as well, @eamonnmcmanus.

@octylFractal octylFractal force-pushed the feature/optional-nested-builders branch from d0cc250 to fbe3414 Compare March 12, 2017 00:06
@raghsriniv raghsriniv added P3 type=enhancement Make an existing feature better labels Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes P3 type=enhancement Make an existing feature better

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants