-
-
Save hjhjw1991/bd13f3278b9f069ef492d71293e8744a to your computer and use it in GitHub Desktop.
Method proxy for Kotlin(verification necessary)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T : Record> T.proxy(): T { | |
return Proxy.newProxyInstance(javaClass.classLoader, | |
arrayOf(Record::class.java), | |
RecordInvocationHandler(this)) as T | |
} | |
class RecordInvocationHandler<T: Record>(private val caller: T) : InvocationHandler { | |
override fun invoke(proxy: Any, method: Method, args: Array<Any>): Any? { | |
var result: Any? = null | |
try { | |
// TODO: Pre-invoke jobs | |
result = method.invoke(caller, *args) | |
// TODO: Post-invoke jobs | |
} catch (ignored: Exception) { | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment