Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get javaclass from java type array in Kotlin?

For pojo classes:

//java
MyClass.getClass();
//kotlin
MyClass::class.java

But how getClass from array?

//java
MyClass[].class;
//kotlin
???

MyClass[]::class.java - does not work :(

like image 784
Cherry Avatar asked Dec 02 '22 12:12

Cherry


1 Answers

It's simple:

Array<String>::class.java
// on objects 
args.javaClass

Arrays in Kotlin don't look as MyClass[], this is Java. Always use Array class with generic types. For primitives there are specialized versions like IntArray.

like image 109
s1m0nw1 Avatar answered Dec 08 '22 03:12

s1m0nw1