fun <E> Set<E>.containsAny(vararg elements: E) = intersect(elements.toSet()).isNotEmpty()
fun test() {
emptySet<String>().containsAny(1, Unit)
}
This compiles in Kotlin, why?
fun <E> Set<E>.containsAny(vararg elements: E) = intersect(elements.toSet()).isNotEmpty()
fun test() {
emptySet<String>().containsAny(1, Unit)
}
This compiles in Kotlin, why?
Because projected type of arguments will be
<Any>
. And the test function can be replaced with:To make the function work properly you have to pass the type explicitly:
Or if possible specify less generic type: