Int和Int类型参数的标识符相等已被弃用

只是fyi,这是我在StackOverflow上的第一个问题,在Kotlin我真的很新。

在完全完成Kotlin(ver 1.1.3-2)的项目时,我在下面的代码中看到了一个警告(对于你好奇的小伙子的评论):

// 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 } } 

警告是针对可见性和View.SYSTEM_UI_FLAG_FULLSCREEN === 0 ,并且它表示不推荐使用类型为Int和Int的参数的标识相等性

我应该如何更改代码,为什么它首先被弃用(为了知识)?

您可以通过使用结构相等来改变代码,如下所示:

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

为什么不建议使用参照平等 ? 你可以在这里看到我的答案。

另一方面,当你使用引用/身份相等可能会返回false ,例如:

 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