「Android/kotlin/singleton」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==singletonサンプル== MainActivity.kt HogeSingleton.setName("hogehoge") Log.i("test", "HogeSingleton.getName()=" + HogeSingleton.getName()) // hogehoge HogeSinglet...」) |
(相違点なし)
|
2020年2月14日 (金) 13:46時点における版
singletonサンプル
MainActivity.kt
HogeSingleton.setName("hogehoge")
Log.i("test", "HogeSingleton.getName()=" + HogeSingleton.getName()) // hogehoge
HogeSingleton.kt
class HogeSingleton {
companion object {
private var name = ""
fun setName(name: String) {
this.name = name
}
fun getName(): String {
return this.name
}
}
}
