I'm writing a Spring Boot app with Spring Data JPA and Kotlin, and I've noticed that in CrudRepository
there is the following method:
Optional<T> findById(ID id);
不过,我使用的是Kotlin,它处理空值的方式比Optional
更流畅.有人知道我该如何把这个方法转换成这样吗?
fun findById(id: ID): T?
When I extend Repository
itself and create a repo with that signature I get the error:
java.lang.ClassCastException: java.util.Optional cannot be cast to com.books.Book