Utilize Kotlin's null-safety features effectively to create cleaner, more robust code: 1. For class properties that will be initialized before use, prefer `lateinit var` over nullable types with `?`:
Utilize Kotlin’s null-safety features effectively to create cleaner, more robust code:
lateinit var
over nullable types with ?
:
```kotlin
// Avoid
private var server: MockWebServer? = null// Prefer private lateinit var server: MockWebServer
2. Design API signatures to minimize forcing clients to use the unsafe `!!` operator:
```kotlin
// Avoid
suspend fun <T : Any> TransactionalOperator.executeAndAwait(f: suspend (ReactiveTransaction) -> T?): T?
// Prefer
suspend fun <T> TransactionalOperator.executeAndAwait(f: suspend (ReactiveTransaction) -> T): T
// Cleaner val ctor = BeanUtils.findPrimaryConstructor(SomeClass::class.java)!! // Continue using ctor directly ```
Enter the URL of a public GitHub repository