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

elect

10/01/2021, 11:04 AM
I'd like to extend this interface and overwrite its method
Copy code
interface WebhookEventInterface<T> {
    operator fun invoke(block: WebhookEventInterface<T>.() -> Unit) {..}
}
in this way
Copy code
interface PushPullRequestFeatures<T> : WebhookEventInterface<T> {
    override operator fun invoke(block: PushPullRequestFeatures<T>.() -> Unit) {..}
}
Unfortunately I didn't find a way to successfully infer the new receiver on the lambda. The above code does not override the super method:
'invoke' overrides nothing
and there is also a platform clash:
Platform declaration clash: The following declarations have the same JVM signature (invoke(Lkyge/triggerEvents/PushPullRequestFeatures;Lkotlin/jvm/functions/Function1;)V):
I've tried to use
@JvmName
, but it says:
'@JvmName' annotation is not applicable to this declaration
I tried also
@OverloadResolutionByLambdaReturnType
by changing the return type, but the clash doesn't go away neither Any idea?
e

ephemient

10/01/2021, 6:01 PM
you can't make it work safely. a consumer can
Copy code
val iface: WebhookEventInterface<T> = object : PushPullRequestFeatures<T> { … }
iface.invoke { // this: WebhookEventInterface<T> ->
e

elect

10/02/2021, 10:22 AM
it turned out I had to convert the receiver type into a type parameter as well https://stackoverflow.com/questions/69403526/dsl-extending-an-interface-method-with-a-lambda-with-receiver-as-argument
2 Views