I want to have for example:
class Foo {
fun doSomething(arg1: String, arg2: String, arg3: Boolean)
}
class FooDelegate {
//different fun name
fun execute by Foo::doSomething
}
Either with reflection or other way.
What I currently have is:
class FooDelegated<R>(
private val func: KFunction<R>
) {
fun execute(vararg params: Any) = func.call(*params)
}
So that I can call
FooDelegated(Foo::doSomething).execute("1", "2", true)
However I require to send parameters which are not really know. I would like my compiler to know which parameters can be sent. Else, I can write the following and it won't fail until run time:
FooDelegated(Foo::doSomething).execute("1", "2", "new argument", false)
NOTE that I want it to have different names, not by using interfaces.
Instead of creating
execute()function, you can createexecuteproperty and keep a function reference there. Then you can use it almost like it is a function:Or:
You can also create a wrapper around
KFunctionto hide its properties likeannotations,isFinal, etc., but keep itsoperator fun invokefunctionality. This would give you more flexibility on what you can do with these functions. It would also make possible to replaceexecuteproperty with a trueexecute()function. However, you would need to create a separate wrapper per number of properties. It could look like this:Still, it sounds like a very strange thing to do. Like you trying to create programming language inside another programming language.