0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?