igor.wojda
02/22/2023, 1:30 PMfun foo(name: String = "noname") {
//...
}
How can I retrieve the default value (noname
) via reflection?ephemient
02/22/2023, 1:32 PMephemient
02/22/2023, 1:36 PMfun foo(name: String = any.complex.expression())
, which is not retained in source form anywhere and not something the reflection api can representAdam S
02/22/2023, 1:47 PMephemient
02/22/2023, 1:48 PMAdam S
02/22/2023, 1:49 PMGoetz Markgraf
02/22/2023, 1:54 PMephemient
02/22/2023, 1:55 PMephemient
02/22/2023, 2:00 PMpublic void foo(String name, int bits) {
if ((bits & 1) == 0) name = "noname"
and Kotlin callers invoke foo("somename", 1)
or foo(null, 0)
ephemient
02/22/2023, 2:01 PMGoetz Markgraf
02/22/2023, 2:01 PMephemient
02/22/2023, 2:04 PM@JvmOverloads
to instruct the compiler to generate more overloads so that Java can call without supplying every parameter, but it only works for dropping parameters at the endephemient
02/22/2023, 2:05 PM@JvmOverloads fun foo(x: Int = 0, y: Int = 0)
Kotlin callers can call foo(x = 1)
and foo(y = 1)
, but Java callers don't have an overload for the latter (how?)