You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Kotlin data classes are great but default parameters quickly diminish the ability for the object to be consumed by Java in an idiomatic fashion.
data class MyObject(val name: String, val age: Int = 0)
class MyObjectBuilder() {
private lateinit var name: String
private var age: Int = 0
fun withName(val name: String) = this.name = name
fun withAge(val age: Int) = this.age = age
fun build() = MyObject(name, age)
}
For non-nullable fields could store them as null in the builder with added validation or just rely on lateinit validation to throw when the property is read during build.
The text was updated successfully, but these errors were encountered:
Kotlin data classes are great but default parameters quickly diminish the ability for the object to be consumed by Java in an idiomatic fashion.
For non-nullable fields could store them as null in the builder with added validation or just rely on lateinit validation to throw when the property is read during build.
The text was updated successfully, but these errors were encountered: