I am writing a Spring Boot application with Spring JPA and Kotlin data, and I noticed that the CrudRepository
following method exists:
Optional<T> findById(ID id);
I use Kotlin, though, which has much faster ways to deal with zeros than Optional
. Does anyone know how I will convert this method to work as follows?
fun findById(id: ID): T?
When I expand Repository
and create a repo with this signature, I get an error:
java.lang.ClassCastException: java.util.Optional cannot be cast to com.books.Book
source
share