Daniele Segato
09/11/2018, 9:59 PMdata class Example(
val something: String = "some default",
val number: Int = 7)
fun test(v: String?, i: Int = -2) {
val a = Example (
something = v ?: ...,// Leave default
number = if (i > 0) i else // default of Example
)
}
With a fluent api of a builder i can do it. Any way kotlin helps me there?
Create with mandatory + use copy()
? Any other (better) way?
Copy creates 1 object every time i use.. a builder interface creates 2: the builder and the object.
EDIT:
Ideally I'd want to do:
fun test(v: String?, i: Int = -2) {
val a = Example (/* mandatory args here */).apply {
if (v !== null) something = v
if (i > 0) number = i
}
But that cant be done with val