Any vs Java Wildcard

Hello,

I’m using a Java Reflections API (GitHub - ronmamo/reflections: Java runtime metadata analysis) 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!!!

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

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

1 Like