I'd like to extend this interface and overwrite it...
# getting-started
e
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
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
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