Created
May 17, 2016 04:41
-
-
Save crowjdh/797c39c68470f0697e41652d4f7faa9f to your computer and use it in GitHub Desktop.
Method proxy for Kotlin(verification necessary)
This file contains hidden or 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