What is the right way of using “greater than”, “less than” comparison on nullable integers in Kotlin?

前端 未结 6 1726
南方客
南方客 2021-01-03 19:00
var _age: Int? = 0

public var isAdult: Boolean? = false
   get() = _age?.compareTo(18) >= 0 

This still gives me a null-safety, compile error,

6条回答
  •  忘掉有多难
    2021-01-03 19:59

    Also can try this:

    var position = 100
    
        mArrayList?.let {
    
                    if (it.size > 0 && position >= 0 ) 
                         return true
    
                }
    

提交回复
热议问题