0
0

[Kotlin] Listenerオブジェクトの中で`this`キーワードを使うとき

Posted at

問題

Listenerオブジェクトの中でthisを使用すると、thisの参照箇所をkotlinが間違える時がある。

解決方法

ラベルを用いて参照箇所を明示する

override fun onListened(property: {TYPE}) {
//    this.property = property // error
    this@{YOUR_CLASS_TYPE}.property = property
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0