Default property initialization for interfaces


#1

In Kotlin we can define properties on an interface, which is great because it means we can create default method implementations that make use of state. What I'd love to see is if we could also define default values for those properties.

I understand that it would have to work a little differently than methods. With methods the interface defines a static method and the auto-generated implementation calls that static method, passing in a receiver object.
Instead of having default properties affect the interface and creating a static property, I imagine the implementation would just use the default value unless multiple interfaces have the same property name, in which case it would need to be overriden (similar to methods, except no super<Foo>.someProperty)

The reason I’d like this is because it makes multiple-inheritance cleaner, where I can have a class implement several interfaces and not have to override all the properties for each one.

interface Foo {   protected var _bar: Int = 0 }

class FooImpl : Foo {
  override protected var _bar: Int = 0   // Redundant line, this would be compiled into FooImpl if there was no override.
}

Also, fixing protected methods and variables in interfaces would really help me a lot :). (KT-3029)


#2

This is not planned for the nearest future