Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's Kotlin equivalent of Class<?>

Tags:

kotlin

I want a map between Int and any class. In Java it would be Map<Class<?>, Integer>. What's the Kotlin equivalent of that?

like image 817
Jack Guo Avatar asked Jun 14 '18 17:06

Jack Guo


People also ask

Does Kotlin support constructor overloading?

Kotlin supports overloading for callables and properties, that is, the ability for several callables (functions or function-like properties) or properties with the same name to coexist in the same scope, with the compiler picking the most suitable one when such entity is referenced.

What is the difference between :: class and :: class Java in Kotlin?

By using ::class , you get an instance of KClass. It is Kotlin Reflection API, that can handle Kotlin features like properties, data classes, etc. By using ::class. java , you get an instance of Class.

What is a KClass Kotlin?

The KClass type is Kotlin's counterpart to Java's java. lang. Class type. It's used to hold references to Kotlin classes; you'll see what it lets you do with those classes in the “Reflection” section later in this chapter. The type parameter of KClass specifies which Kotlin classes can be referred to by this reference.


1 Answers

The equivalent declaration would be Map<Class<*>, Int>.

like image 130
EpicPandaForce Avatar answered Sep 23 '22 11:09

EpicPandaForce