There are some interfaces or classes blow:
interface ITagProvider {
fun getTag(): String
}
interface ITagPrinter {
fun printTag()
}
class TagPrinter(val tagProvider: ITagProvider): ITagPrinter {
override fun printTag() {
print(tagProvider.getTag())
}
}
When using Kotlin delegate to implement the following class, the IDE prompts "'this' is not defined in this context."
class AnyClass: ITagPrinter by TagPrinter(this), ITagProvider {
override fun getTag() = "AnyClass"
}
I understand that at this moment, an instance of AnyClass
has not been created yet. However, how can we achieve this effect? In other words, how can we access the methods of the delegated class(AnyClass
) within the proxy class(TagPrinter
)?