{"action":"created","issue":{"url":"https://api.github.com/repos/google/auto/issues/278","labels_url":"https://api.github.com/repos/google/auto/issues/278/labels{/name}","comments_url":"https://api.github.com/repos/google/auto/issues/278/comments","events_url":"https://api.github.com/repos/google/auto/issues/278/events","html_url":"https://github.com/google/auto/issues/278","id":112692332,"number":278,"title":"AutoValue: Support Optional<T> similar to @Nullable","user":{"login":"mfulton26","id":5588957,"avatar_url":"https://avatars.githubusercontent.com/u/5588957?v=3","gravatar_id":"","url":"https://api.github.com/users/mfulton26","html_url":"https://github.com/mfulton26","followers_url":"https://api.github.com/users/mfulton26/followers","following_url":"https://api.github.com/users/mfulton26/following{/other_user}","gists_url":"https://api.github.com/users/mfulton26/gists{/gist_id}","starred_url":"https://api.github.com/users/mfulton26/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mfulton26/subscriptions","organizations_url":"https://api.github.com/users/mfulton26/orgs","repos_url":"https://api.github.com/users/mfulton26/repos","events_url":"https://api.github.com/users/mfulton26/events{/privacy}","received_events_url":"https://api.github.com/users/mfulton26/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-21T22:29:59Z","updated_at":"2015-10-21T23:02:26Z","closed_at":null,"body":"I'd like to have \"optional\" value properties but instead of annotating my properties with `@Nullable` and then checking for `null` when using the property I'd rather use [`java.util.Optional<T>`](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html) and/or [`com.google.common.base.Optional<T>`](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Optional.html).\r\n\r\nHere's what I'm doing today:\r\n```java\r\nimport com.google.auto.value.AutoValue;\r\n\r\nimport java.util.Optional;\r\n\r\nclass Example {\r\n  @AutoValue\r\n  abstract static class Animal {\r\n    static Builder builder() {\r\n      return new AutoValue_Example_Animal.Builder()\r\n          .name(Optional.empty)\r\n          .numberOfLegs(Optional.empty());\r\n    }\r\n\r\n    abstract Optional<String> name();\r\n    abstract Optional<Integer> numberOfLegs();\r\n\r\n    @AutoValue.Builder\r\n    abstract static class Builder {\r\n      Builder name(String s) { return name(Optional.ofNullable(s)); }\r\n      abstract Builder name(Optional<String> s);\r\n      Builder name(Integer n) { return name(Optional.ofNullable(n)); }\r\n      abstract Builder numberOfLegs(Optional<Integer> n);\r\n      abstract Animal build();\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nHere's what I want to do:\r\n```java\r\nimport com.google.auto.value.AutoValue;\r\n\r\nimport java.util.Optional;\r\n\r\nclass Example {\r\n  @AutoValue\r\n  abstract static class Animal {\r\n    static Builder builder() {\r\n      return new AutoValue_Example_Animal.Builder();\r\n    }\r\n\r\n    abstract Optional<String> name();\r\n    abstract Optional<Integer> numberOfLegs();\r\n\r\n    @AutoValue.Builder\r\n    abstract static class Builder {\r\n      abstract Builder name(String s);\r\n      abstract Builder numberOfLegs(Integer n);\r\n      abstract Animal build();\r\n    }\r\n  }\r\n}\r\n```\r\n\r\ni.e. I want `Optional<T>` properties to default to [`Optional.empty()`](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#empty--)/[`Optional.absent()`](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Optional.html#absent()) instead of `null` and to be able to define `Builder` methods (or constructors) that use `T` instead of `Optional<T>`. I'm using [`Optional.ofNullable(T)`](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#ofNullable-T-)/[`Optional.fromNullable(T)`](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Optional.html#fromNullable(T)) instead of [`Optional.of(T)`](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#of-T-)/[`Optional.of(T)`](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Optional.html#of(T)) so that I can still set a property to [`Optional.empty()`](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#empty--)/[`Optional.absent()`](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Optional.html#absent()) by passing in `null` to the appropriate `Builder` method."},"comment":{"url":"https://api.github.com/repos/google/auto/issues/comments/150048397","html_url":"https://github.com/google/auto/issues/278#issuecomment-150048397","issue_url":"https://api.github.com/repos/google/auto/issues/278","id":150048397,"user":{"login":"eamonnmcmanus","id":5246810,"avatar_url":"https://avatars.githubusercontent.com/u/5246810?v=3","gravatar_id":"","url":"https://api.github.com/users/eamonnmcmanus","html_url":"https://github.com/eamonnmcmanus","followers_url":"https://api.github.com/users/eamonnmcmanus/followers","following_url":"https://api.github.com/users/eamonnmcmanus/following{/other_user}","gists_url":"https://api.github.com/users/eamonnmcmanus/gists{/gist_id}","starred_url":"https://api.github.com/users/eamonnmcmanus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eamonnmcmanus/subscriptions","organizations_url":"https://api.github.com/users/eamonnmcmanus/orgs","repos_url":"https://api.github.com/users/eamonnmcmanus/repos","events_url":"https://api.github.com/users/eamonnmcmanus/events{/privacy}","received_events_url":"https://api.github.com/users/eamonnmcmanus/received_events","type":"User","site_admin":false},"created_at":"2015-10-21T23:02:25Z","updated_at":"2015-10-21T23:02:25Z","body":"Yes, we already have a Google-internal issue tracking this."}}