Best way to handle such scenario where “smart cast is imposible”

前端 未结 7 774
鱼传尺愫
鱼传尺愫 2020-12-20 17:33

I wonder what is the best way to handle such scenario

class Person(var name:String? = null, var age:Int? = null){
    fun test(){
        if(name != null &am         


        
7条回答
  •  生来不讨喜
    2020-12-20 18:27

    I was having the problem while assigning text to textview with same problem description. All I did was putting double exclamation mark after the name of my textview. For example:

    var name:TextView?=null
    name = findViewById(R.id.id_name)
    name!!.text = "Your text"
    

提交回复
热议问题