Is it possible to define your own delegate for interface delegation?
I know I could just do:
interface Foo {
val aaa: String
val bbb: Int
val ccc: Date
}
class Bar() : Foo {
val aaa: String by myDelegate()
val bbb: Int by myDelegate()
val ccc: Date by myDelegate()
}
but that would get tedious pretty soon if you had to do this with many classes with many properties. Wouldn’t it be much nicer to be able to do?:
class Bar(myDelegate) : Foo by myDelegate()
Edit: re-reading I realize it might not be obvious why I want this. Basically I want the by Map
functionality on entire interfaces, so I´d want something like this:
class Bar(map: Map<String, Any>) : Foo {
val aaa: String by map
val bbb: Int by map
val ccc: Date by map
}
to be turned into:
class Bar(map: Map<String, Any>) : Foo by map
but that doesn’t work, but I could implement it if I could implement a custom delegate for interfaces.