hey guys, scratching my head over `@JvmOverloads` ...
# announcements
c
hey guys, scratching my head over
@JvmOverloads
on a data class constructor- it doesn’t seem that every permutation of the constructor is created to match default parameters
g
@JvmOverloads doesn’t create every permutation
c
attempting to provide a sane API for a java client when I have a data class like:
Copy code
data class Foo @JvmOverloads constructor(bar: String, baz: Int, dimble: Int? = null, farb: Int? = 20)
And I’m getting a handful of constructors generated
which permutations does it generate? how can I get it to generate more? or how do I hand roll my own constructors?
g
It will just create overloads with -1 argument
k
JvmOverloads generate just the "tailing" overloads with default args.
g
yes, tailing is good word for this behavior
If it would generate every permutations, for 10 arguments it would create how many, 1000 constructors?
k
I believe it's
10!
🙂
g
Yeah, may be
anyway, it wouldn’t work, because it doesn’t work if params have the same type
c
creating manual overloads of the constructor it is then 👍 thanks guys
g
Also I found that builder function with some meaningful name is better choice for Java interop than secondary constructors which harder write and which pollute constructor completion for Kotlin
👍 1