My codebase is a mix of java and kotlin code. I would like to use the @JvmOverloads method for an interface with default arguments. For instance:
@JvmOverloads fun getClientCompanyId(clientId: Long, date: DateTime = DateTime.now()): Long
I cannot do this, unfortunately, and I get a message that:
JvmOverloads cannot be used for interface methods
However, if I use it with an overridden function, I get
Collision with a platform declaration: The following declarations have the same JVM signature (getClientCompanyId (JLorg / joda / time / DateTime;) J):
- @JvmOverloads public open fun getClientCompanyId (clientId: Long, date: DateTime = ...): Long
- @JvmOverloads public open fun getClientCompanyId (clientId: Long, date: DateTime = ...): Long
and just for the record: when I try to put the default value in an overridden method, I get a message stating that:
Prohibiting function cannot specify default values ββfor its parameters
Can this be done in Kotlin? Thanks for all the answers.
source share