8

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 :(

1
  • Java syntax would actually be .class, not .getClass() Commented Oct 23, 2017 at 14:47

1 Answer 1

23

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This works but won't if List is used instead of Array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.