Identity equality for Int and Int type arguments is deprecated
Just fyi, this is my first question on StackOverflow and I am really new to Kotlin.
While working on a project that is completely Kotlin (version 1.1.3-2), I see a warning in the following code (with comments for you nosy guys):
// 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 that identity equality for Int and Int type arguments is deprecated.
How do I change the code and why was it deprecated in the first place (for the sake of knowledge)?
source to share
You can change the code using structural equality as shown below:
// use structual equality instead ---v
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
decorView.systemUiVisibility = flags
}
Why not suggest using reference equality ? you can see my answer here .
On the other hand, when you are using referential / id equality , perhaps 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
source to share