Joe
02/26/2019, 5:38 PMMap<String, (Int)->Boolean>
and a Map<String, (String)->Boolean>
. I'd like to combine them to get a Map<String, (Any)->Boolean>
, but can't quite figure out how to do so safely. I can safely cast to Map<String, *>
or Map<String, Any?>
without an unchecked cast warning, but I can't safely cast to `Map<String, (*)->Boolean>`(compile error) or Map<String, (Any?)->Boolean>
(unchecked cast)Ruckus
02/26/2019, 5:45 PMMap<String, (Int) -> Boolean>
and cast it to Map<String, (Any) -> Boolean>
, what do you expect to happen if you do map["key"]("fred")
?Ruckus
02/26/2019, 5:46 PMJoe
02/26/2019, 5:55 PMMap<String, Any?>
?Ruckus
02/26/2019, 5:58 PMAny?
. That is a concrete type. Function types (like (Int) -> Boolean
) are generic, and are internally represented as something like Function<in Int, out Boolean>
.Ruckus
02/26/2019, 5:59 PMAny?
you can do to (Int) -> Boolean
. The same isn't true for (Int) -> Boolean
and (Any) -> Boolean
as my example showed.robstoll
02/26/2019, 6:24 PMMap<String, Pair<KClass<*>, (Any) -> Boolean>>
and you would need to apply the check for the parameter based on the KClass during runtime to stay safe.Joe
02/26/2019, 10:42 PMPredicateGenerator<T>
that takes a <T>
value in its constructor args, but exposes a getPredicate() that returns T/F based on the constructor args. Then I can, for example, AND a bunch of those together without having to know about the "inner" generic instance.