LoginSignup
0
0

More than 5 years have passed since last update.

setterでStack Overflowしないために

Posted at

Kotlinではプロパティに対して自動的にgetter/setterを生成してくれる。
とっても有り難いのです

そしてそれを下のように書いてしまうと・・・?

class Hoge {
  var foo : String
    set(value){
      foo = value
    }
}

正しくは以下の通りにfieldと書きましょう

class Hoge {
  var foo : String
    set(value){
      field = value
    }
}
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