In Android there are lots of methods where you override a method in the superclass, but are required to call the super class implementation (it is checked to make sure you did). So you have many methods that look something like this:
override fun onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?)
{
super.onSaveInstanceState(outState, outPersistentState)
doSomething()
}
Which is a lot of ceremony and duplication of variable and function names and it prevents you from doing things like using an expression body for the method.
I find myself wishing if Kotlin had some shorthand you could add to the method signature to tell the compiler to generate the call to the super implemenation for me.
Not sure what the syntax of that might be, but would probably involve the word super somewhere. One thought I had was that it would kind of be like class delegation and property delegation so perhaps something using the by keyword might be a good start:
override fun onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?)
by super = doSomething()
This could also support parameters to super if you want to pass something other than the actual parameters
override fun foo(a:Int) by super(a+1) { }
But there could be some ambiguity if the method parameter were a function and knowing if the braces were a lambda to pass to super or the body of this method. That could be solved by requiring the parentheses on super. The super would act like function with all parameters defaulted to the parameters passed to this implementation so that if the method had multiple parameters and you only wanted to change some you could use named arguments:
override fun baz(a: Int, b:Int) by super(b = 5) { }
would be equivalent to
override fun baz(a: Int, b:Int) = super.baz(a, 5)
But then how do you access the return value of the super call? Perhaps the body is then looked at as a lambda and the result of the super call is passed as a parameter.