Type inference failed on function "enumSetOf"


In the following function

enum class TestEnum {A, B, C }

inline fun <reified T : java.lang.Enum<T>> enumSetOf(vararg elems: T) =
        java.util.EnumSet.noneOf(T::class.java).apply {

fun main(args: Array<String>) {

method noneOf has type inference failed “T isn’t a subtype of Enum”


It’s not without reason java.lang.Enum is highlighted in IDE with the warning:

This class shouldn’t be used in Kotlin. Use kotlin.Enum instead.

If you use kotlin.Enum (just Enum), enumSetOf is compiled without any error.