Kotlin feature request


or if this is the existing feature

I’m not exactly the name of such method (Note that it is not extension method, it reside with in a class)

override fun Canvas.onDrawWithMatrix() {
    val staticLayout = staticLayoutVO.value ?: return
    if (top != -1f && left != -1f) {
        translate(left, top)

is there way to call super method?

example being:


It even shows you the syntax in the popup.

override fun foo() {
    // some other code

the function is

override fun Canvas.onDrawWithMatrix() {
val staticLayout = staticLayoutVO.value ?: return
if (top != -1f && left != -1f) {
    translate(left, top)


it’s different than normal ones

I also looked the decompiled java code


super.onDraw(this) doesn’t work?


It won’t work since this method was called from that one so it will end up an infinite loop


Is this an API under your control? Why do you use an extension function here? What do you want to accomplish that wouldn’t be possible without extension functions?

There was a related topic in this forum.


Somethings not right here. You shouldn’t be able to override a function you can’t call. That’s simply not how the JVM works. I guess that your intelli-sense is not working.
Try to use super.onDrawWithMatrix() and if this does not work, maybe post the compiler error.
Also just out of curiosity, what editor are you using?


As @medium pointed out, you can’t call superclass implementation of overridden extension functions as I found out 3 years ago. Please upvote the bug tracking this: https://youtrack.jetbrains.com/issue/KT-11488


the way to call it is canvas.onDrawWithMatrix() however it can only be called from within the super class.

(as you can see from the right section of the second screenshot)


Since you don’t want to post the compiler error, I’ll do it for you :wink:. I reproduced your problem

Error:(9, 9) Kotlin: Abstract member cannot be accessed directly

This should explain why you can’t and wont ever be able to call super.onDrawWithMatrix()


i don’t mind sharing my code it’s just I’ve already changed the related code and can’t be bothered.

your error indicates that the super method you are trying override is abstract, and it’s not my case at all.

btw I’m using latest android studio canary




ofcourse, not where you are looking for, but if you have java7, you can temporarily use this workaround:

override fun String.concate() : String {
    return MethodHandles.lookup().findSpecial(
        A::class.java, "concate",
        MethodType.methodType(String::class.java, String::class.java),
    ).invokeWithArguments(this@B, this) as String