https://kotlinlang.org logo
Title
c

Czar

12/25/2018, 12:41 PM
Is there a nice pattern to avoid unnecessary null checks, like following?
@Entity class MyEntity(val id: Long?, ...)
val myEntity = myEntityRepository.getById(1L)
// fun useMyEntityId(id: Long) {...}
useMyEntityId(checkNotNull(myEntity.id)) // check here is logically unnecessary, since entity retrieved from database will always have id
I'm asking in general, but if there is anything specific for Spring Boot and Hibernate, that would be also interesting.
Solved.
@Entity class MyEntity(val id: Long = 0L, ...)
just works 😄