如何使用构造函数中具有参数的类的反射创建对象实例?

时间:2020-03-26 06:20:28

标签: android kotlin reflection

我正在尝试使用反射和具有在构造函数中具有参数的类的对象来创建对象。

这是我在没有构造函数的情况下尝试的方法。

ABC::class.createInstance()

但是我不知道如何在像这样的构造函数的类中做到这一点

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

1 个答案:

答案 0 :(得分:1)

ABC::class.getConstructor(Int::class, Int::class).newInstance(firstInt, secondInt)