How to write strongly typed generic extension function in Kotlin?
问题 Focus on the strong and generic parts. Let's say I have this extension function: fun <E> Collection<E>.myContains(item: E) : Boolean { // quite pointless, I know, but a simple example return item in this } the intention is to write a function that only accepts types of the collection elements ( E ), but this is not validated by the compiler?! val isItInside: Boolean = listOf(1, 2).myContains("1") happily compiles. My guess is that E is inferred to be Any . How can I enforce this restriction