I am very new to Kotlin programming language. Null safety is a very interesting feature. But in real life programming where I used to use null, how to deal with those ? Like following example :
@Service
open class OrganizationService(val orgRepo: OrganizationRepository) {
@Transactional
open fun findByName(name: String): Organization? {
return orgRepo.findByName(name)
}
}
This is a very simple spring service layer, where I am retrieving data using Spring Data JPA
. It is very common to check null whether the data is in DB or not. So I need to put ?
in the return type to tell compiler that return type Organization could be null. Then I have to carry out this ?
in everywhere I am going to use this object. Literary I need to check if(org != null)...
.Could Kotlin Null Safety help out this type of scenario ?
Thanks.