tim
02/29/2020, 12:27 PMmatcher: (x: Any) -> Boolean
. Later when i pass in a lambda for matcher, I have to cast from Any to the concrete type as per blew. Is there a better way to do this?
data class Query(
matcher: (x: Any) -> Boolean
)
...
val query = Query(
matcher: { x: Any? ->
val value = x as Int?
if(value == null || value == 0) false else true
}
)
Mark Murphy
02/29/2020, 1:02 PMclass Query<T>(
val matcher: (x: T) -> Boolean
)
val query = Query { value: Int ->
if (value == 0) false else true
}
fun main() {
println(query.matcher(0))
println(query.matcher(1))
}
tim
02/29/2020, 1:07 PMKroppeb
02/29/2020, 2:33 PMclass Query<in T>