title: How to assign or set an Optional<String> value to a String variable?
body: <p>I am trying to set an <code>Optional&lt;String&gt;</code> value returned from a method to a setter method of a model class.</p>
  
  <pre><code>public class Person{
  
      private String address;
  
      public void setAddress(String Address){
          address = Address;
      }
  
      public String getAddress(){
          return address;
      }
  
  }
  </code></pre>
  
  <p>This what i tried out</p>
  
  <pre><code>Person person = new Person();    
  Optional&lt;String&gt; addr = retrievePersonAddressById(5);
  if (addr.isPresent()) {
      person.setAddress(addr.get());
  }
  </code></pre>
  
  <p>But i got </p>
  
  <pre><code>incompatible types: String cannot be converted to Optional&lt;String&gt;
  </code></pre>
  
  <p>Note:</p>
  
  <p>retrievePersonAddressById() has a return type of <code>Optional&lt;string&gt;</code>.</p>
  
  <p>The error is on line</p>
  
  <pre><code>person.setAddress(addr.get());
  </code></pre>
  
  <p>I need help please</p>