Martin Barth
11/08/2021, 10:23 AM"-" -> if (aggregate is Minus) Minus(*aggregate.expressions, nextExpression) else Minus(aggregate, nextExpression)
"+" -> if (aggregate is Plus) Plus(*aggregate.expressions, nextExpression) else Plus(aggregate, nextExpression)
....
I wanted to make that easier, but i am failing. My Idea was something like this:
private inline fun <reified T> myIdea(aggregate: InfixExpression, nextExpression: Expression): T = if (aggregate is T)
T(*aggregate.expressions, nextExpression)
else
T(aggregate, nextExpression)
using the Type T as a Constructor does not work. Any advice?Michael de Kaste
11/08/2021, 10:38 AMVampire
11/08/2021, 10:38 AMT
will be, it cannot know which constructors would exist, so I don't think this is possible directly.
You need to resort to reflection.
Use T::class.constructors
or T::class.java.getConstructor(type1, type2)
to find the constructor you want to invoke and then call it.Chris Black
11/09/2021, 4:11 PM