0

I'm trying to create object using reflection with class that have parameter in constructor.

This is what I try for class without constructor.

ABC::class.createInstance()

But I have no idea how to do this for class with constructor like

class ABC(a: Int, b: Int) {}

1 Answer 1

1
ABC::class.getConstructor(Int::class, Int::class).newInstance(firstInt, secondInt)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank so much. It's works. Anyway, are there any possible solution for kotlin.reflect to do something like this?

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.