Any vs Java Wildcard


#1

Hello,

I’m using a Java Reflections API (https://github.com/ronmamo/reflections) that returns a Set of Class<?> (Set>), i trying to assign the returned Set to a Class property declared by:

  `var serverClasses : Set<Class<Any>> = hashSetOf<Class<Any>>();`

And i’m getting this error:

Type mismatch.
Required: Set<Class>
Found: (Mutable)Set<Class<*>!>!

Klotin “Any” keyword is similar to Java Generics Wildcard?

Thank you!!!


#2

Any corresponds to java.lang.Object, not to a wildcard.

Please refer to http://kotlinlang.org/docs/reference/generics.html#star-projections