Identity equality for arguments of types Int and Int is deprecated

蓝咒 提交于 2019-12-14 00:46:12

问题


Just fyi, this is my first question on StackOverflow and I'm really new in Kotlin.

While working on a project that's fully Kotlin (ver 1.1.3-2), I see a warning on the following code (with the comments for you curious lads):

    // Code below is to handle presses of Volume up or Volume down.
    // Without this, after pressing volume buttons, the navigation bar will
    // show up and won't hide
    val decorView = window.decorView
    decorView
        .setOnSystemUiVisibilityChangeListener { visibility ->
            if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN === 0) {
                 decorView.systemUiVisibility = flags
            }
        }

The warning is for visibility and View.SYSTEM_UI_FLAG_FULLSCREEN === 0, and it says Identity equality for arguments of types Int and Int is deprecated.

How should I change the code and why was it deprecated in the first place (for knowledge's sake)?


回答1:


You can change the code by using structual equality instead as below:

//              use structual equality instead ---v
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
    decorView.systemUiVisibility = flags
}

Why don't suggest to use referential equality? you can see my answer here.

On the other hand, when you use referential/identity equality maybe return false, for example:

val ranged = arrayListOf(127, 127)

println(ranged[0] === ranged[1]) // true
println(ranged[0] ==  ranged[1]) // true

val exclusive = arrayListOf(128, 128)

//                                        v--- print `false` here
println(exclusive[0] === exclusive[1]) // false
println(exclusive[0] ==  exclusive[1]) // true


来源:https://stackoverflow.com/questions/45222144/identity-equality-for-arguments-of-types-int-and-int-is-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!