DavidGSola:
私は、ヘッダがあるプライベートメソッドを持っています。
private fun setNumericListener(editText: EditText, onValueChanged:(newValue: Double?) -> Unit)
私はこのように、このメソッドを呼び出します。 setNumericListener(amountEditText, this::onAmountChanged)
私はクラスからgetDeclaredMethodを使用したいhttps://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getDeclaredMethod(java.lang.String,%20java.lang.Class .. 。)私のプライベートメソッドへの参照を取得しますsetNumericListener
。getDeclaredMethod
パラメータの型の配列を受け取りClass<?>... parameterTypes
ますが、私は私のプライベートメソッドは、パラメータとしてメソッド参照を持っている場合、パラメータの型の配列を設定する方法については考えています。
感謝
ロビーCornelissen:
関数参照がタイプとして解決されますkotlin.jvm.functions.Function1
。
これは、あなたが使用できることを意味getDeclaredMethod()
呼び出すことによって、メソッド参照を取得するには:
getDeclaredMethod("setNumericListener", EditText::class.java, Function1::class.java)
ここでは、完全な抜粋です:
fun main(vararg args: String) {
val method = Test::class.java.getDeclaredMethod("setNumericListener",
EditText::class.java, Function1::class.java)
println(method)
}
// Declarations
class Test {
private fun setNumericListener(editText: EditText,
onValueChanged: (d: Double?) -> Unit) {}
}
class EditText {}
どのプリント:
private final void Test.setNumericListener(EditText,kotlin.jvm.functions.Function1)