title: Spring Data JPA How to use Kotlin nulls instead of Optional
body: <p>I'm writing a Spring Boot app with Spring Data JPA and Kotlin, and I've noticed that in <code>CrudRepository</code> there is the following method:</p>
  
  <pre><code>Optional&lt;T&gt; findById(ID id);
  </code></pre>
  
  <p>I'm using Kotlin, though, which has much more fluent ways of dealing with nulls than <code>Optional</code>. Does anyone know how I would convert that method to work like this?</p>
  
  <pre><code>fun findById(id: ID): T?
  </code></pre>
  
  <p>When I extend <code>Repository</code> itself and create a repo with that signature I get the error:</p>
  
  <pre><code>java.lang.ClassCastException: java.util.Optional cannot be cast to com.books.Book
  </code></pre>