の最初の引数であってもよいが、のはKCallable
のドキュメントを見てみましょう必要があります。引数の数がある場合
/**
* Calls this callable with the specified list of arguments and returns the result.
* Throws an exception if the number of specified arguments is not equal to the size of [parameters],
* or if their types do not match the types of the parameters
*/
public fun call(vararg args: Any?): R
は、」例外をスローします[parameters] [...]のサイズと同じではありません。 「そのために、この呼び出し可能にthis
インスタンスを必要とする場合は、[...] [それは]最初のリストに[s]が来る。」
/**
* Parameters required to make a call to this callable.
* If this callable requires a `this` instance or an extension receiver parameter,
* they come first in the list in that order.
*/
public val parameters: List<KParameter>
:一方、パラメータ次のDOCとList<KParameter>
です
ベニールは既に正しく答えられているように、this
インスタンスが最初のパラメータであり、メソッドが呼び出される必要があるため、残りの3つのパラメータの前に来ます。
あなたはparameter
のコンテンツを見たときあなたはそれを見ることができます:
class X{
fun before(action: String, request: String, response: String)= println("called")
}
fun main(args: Array<String>) {
X::class.functions.forEach { function: KFunction<*> ->
if (function.name == "before") {
function.parameters.forEach{ println(it)}
//function.call(X(), "a", "b", "c")
}
}
}
を印刷parameter
次のようになります。
instance of fun de.swirtz.jugcdemo.prepared.X.before(kotlin.String, kotlin.String, kotlin.String): kotlin.Unit
parameter #1 action of fun de.swirtz.jugcdemo.prepared.X.before(kotlin.String, kotlin.String, kotlin.String): kotlin.Unit
parameter #2 request of fun de.swirtz.jugcdemo.prepared.X.before(kotlin.String, kotlin.String, kotlin.String): kotlin.Unit
parameter #3 response of fun de.swirtz.jugcdemo.prepared.X.before(kotlin.String, kotlin.String, kotlin.String): kotlin.Unit
ああ、はい、明らかにそれを呼び出すためにインスタンスを必要とします。 –