sound.idプロパティをnullableからnullnableに変換し、param of playメソッドとして渡すのに最適な方法は何ですか?null可能なプロパティにアクセスする方法はありますか?
class Sound() {
var id: Int? = null
}
val sound = Sound()
...
//smarcat imposible becouse 'sound.id' is mutable property that
//could have changed by this time
if(sound.id != null)
soundPool.play(sound.id, 1F, 1F, 1, 0, 1F)
//smarcat imposible becouse 'sound.id' is mutable property that
//could have changed by this time
sound.id?.let {
soundPool.play(sound.id, 1F, 1F, 1, 0, 1F)
}
チェック:http://stackoverflow.com/questions/34498562/in-kotlin-what-is-the-idiomatic-way-to-deal-with-nullable-values-referencing-o – piotrek1543