我的方法中这样的IF太多:
if (myObject?.name !=null)
first.text = myObject.name.bigThing
if (myObject?.age !=null)
second.text = myObject.age.bigThing
if (myObject?.surname !=null)
third.text = myObject.surname.bigThing
还有20个...
如何缩短代码?
age/surname/name
是使用Big
和id: Int
输入我自己的类bigThing: String
最佳答案
一种方法是:
myObject?.age?.let { second.text = it.bigThing }
如果要将值放在
TextView
中:first.text = myObject?.age?.bigThing
关于kotlin - 我的情况下IF的减少数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51486857/