From 0599ce91b1631ef46a73234354ae9beaec9b0808 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 12 Jun 2023 15:08:42 +0900 Subject: [PATCH] reflection function update --- src/net/torvald/reflection/Reflection.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net/torvald/reflection/Reflection.kt b/src/net/torvald/reflection/Reflection.kt index 919c8119b..3733baf18 100644 --- a/src/net/torvald/reflection/Reflection.kt +++ b/src/net/torvald/reflection/Reflection.kt @@ -3,15 +3,15 @@ package net.torvald.reflection /** * Created by minjaesong on 2023-03-25. */ -fun Any.extortField(name: String): Any? { // yes I'm deliberately using negative words for the function name +inline fun Any.extortField(name: String): T? { // yes I'm deliberately using negative words for the function name return this.javaClass.getDeclaredField(name).let { it.isAccessible = true - it.get(this) + it.get(this) as T? } } -fun Any.forceInvoke(name: String, params: Array): Any? { // yes I'm deliberately using negative words for the function name +inline fun Any.forceInvoke(name: String, params: Array): T? { // yes I'm deliberately using negative words for the function name return this.javaClass.getDeclaredMethod(name, *(params.map { it.javaClass }.toTypedArray())).let { it.isAccessible = true - it.invoke(this, *params) + it.invoke(this, *params) as T? } } \ No newline at end of file