Is there a way to conditionally declare constructo...
# announcements
d
Is there a way to conditionally declare constructor / function parameters?
Copy code
data 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:
Copy code
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