Android/kotlin/基本
提供: 初心者エンジニアの簡易メモ
null許可
var name: String = null // これだと入らない var title: String? = null // ?をつけるとnullが許可される
読み込みのみ
valを使う
val description = "hoge" description = "hoge2" // 許可されない
nullじゃない時の値
text1.setText(name ?: "hello");
型
Int // 数字 String // 文字 Boolean // 真偽 Array<String> // 文字配列 Unit // voidみたいなもの、Unitは省略可能
for
for (name: String in names) {
// name
}
空やnull判定
var name: String? = null
if (TextUtils.isEmpty(name)) {
Log.i("exists", "empty") // "", null
} else {
Log.i("exists", "not empty")// "hoge"
}
