Daniel Branco
09/11/2021, 10:01 AMdata class Foo(
var id: Int?,
var name: String = "bar",
var anotherVar
)
I thought I could have calls like Foo()
or Foo(id=1)
without needing to pass all the parameters to the constructor, am I wrong? Where can I read more about constructors in Kotlin?ephemient
09/11/2021, 10:06 AMephemient
09/11/2021, 10:07 AMid
or anotherVar
, both must be specifiedephemient
09/11/2021, 10:08 AMname
is optional and precedes a required argument, anotherVar
must be given by name if name
is omittedephemient
09/11/2021, 10:08 AMDaniel Branco
09/11/2021, 10:29 AMStephan Schroeder
09/11/2021, 7:13 PManotherVar
needs a type. Candiates:
• Any
or Any?
(like Any
but nullable) if you want to put anything in it.
• Or you make Foo
generic:
data class Foo<T> {
var id: Int?,
var name: String = "bar",
var anotherVar: T
)
but since you're new to Kotlin maybe generics are too advanced??