Good Code
The good version turns a nullable title into a domain decision before the Review object exists.
Lesson 01
Keep nullable values at input boundaries instead of spreading !! through service code.
data class Review(val title: String)
fun createReview(title: String?): Review? {
// Nullable input is checked before service code builds the Review.
val normalized = title?.trim()?.takeIf { it.isNotEmpty() } ?: return null
return Review(normalized)
}data class Review(val title: String)
fun createReview(title: String?): Review {
// The crash moves request validation into a hidden runtime branch.
return Review(title!!.trim())
}The good version turns a nullable title into a domain decision before the Review object exists.
The bad version uses !!, so a missing title becomes a runtime crash instead of a validation result.