https://kotlinlang.org logo
#getting-started
Title
# getting-started
t

tipsy

08/12/2020, 12:44 PM
what's the easiest way of making this interoperable with java?
class MyClass(val arg1: String, val arg2: String? = null)
(making it generate two constructors)
t

tipsy

08/12/2020, 12:48 PM
This annotation is not applicable to target 'class'
i need to pull out the constructor and then annotate that?
d

diesieben07

08/12/2020, 12:51 PM
class MyClass @JvmOverloads constructor(...)
No need to pull it out, just need to be a bit more specific
t

tipsy

08/12/2020, 12:53 PM
:l
thanks!
could not have imagined that being valid syntax
j

Joost Klitsie

08/12/2020, 1:50 PM
why not? 🙂 you want to annotate the constructor so it will create the JVMOverloads for you, which is an operation on the constructor and not on the class
n

nanodeath

08/12/2020, 2:47 PM
it does look a little weird (spelling out
constructor
like that) but it is documented here: • https://kotlinlang.org/docs/reference/annotations.html#usagehttps://kotlinlang.org/docs/reference/classes.html#constructors
👍 1
4 Views