Issue
val finalValue: Array<String> = arrayOf("A", "B", "C", "D")
when (value) {
in finalValue -> println("Pass")
!in finalValue -> println("Not Pass")
}
Error: Kotlin: Type inference failed. The value of the type parameter T should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly.
can you help me to solve this error? thanks
Solution
Assuming that value
is of type Char
(based on your code in the comment)
You are trying to search a Char
in a array of String
. To fix this, you either need to change the array to Array<Char>
or convert the value
to String using toString
val value = 'A'
val finalValue: Array<Char> = arrayOf('A', 'B', 'C', 'D')
when (value) {
in finalValue -> println("Pass")
!in finalValue -> println("Not Pass")
}
or
val value = 'A'
val finalValue: Array<String> = arrayOf("A", "B", "C", "D")
when (value.toString()) {
in finalValue -> println("Pass")
!in finalValue -> println("Not Pass")
}
Answered By - sidgate
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.