title: Java records with nullable components
body: <p>I really like the addition of records in Java 14, at least as a preview feature, as it helps to reduce my need to use lombok for simple, immutable &quot;data holders&quot;. But I'm having an issue with the implementation of nullable components. I'm trying to avoid returning <code>null</code> in my codebase to indicate that a value might not be present. Therefore I currently often use something like the following pattern with lombok.</p>
  <pre><code>@Value
  public class MyClass {
   String id;
   @Nullable String value;
  
   Optional&lt;String&gt; getValue() { // overwrite the generated getter
    return Optional.ofNullable(this.value);
   }
  }
  </code></pre>
  <p>When I try the same pattern now with records, this is not allowed stating <code>incorrect component accessor return type</code>.</p>
  <pre><code>record MyRecord (String id, @Nullable String value){
   Optional&lt;String&gt; value(){
    return Optional.ofNullable(this.value); 
   }
  }
  </code></pre>
  <p>Since I thought the usage of <code>Optional</code>s as return types is now preferred, I'm really wondering why this restriction is in place. Is my understanding of the usage wrong? How can I achieve the same, without adding another accessor with another signature which does not hide the default one? Should <code>Optional</code> not be used in this case at all?</p>