Last active
January 30, 2024 21:48
-
-
Save lukeknxt/44f2ae5695fb73db51b5d0db66a047b2 to your computer and use it in GitHub Desktop.
Kotlin happily infers Any for you
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Wrapper(val id: String) | |
val ids = listOf("id1", "id2") | |
listOf( | |
Wrapper("id1").id, | |
Wrapper("id2") | |
).forEach { someId -> // inferred as Any | |
val result = ids.find { it == someId } | |
// id2 will never be found, but the compiler won't tell you | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment