A lightweight Kotlin wrapper of the Proxy API.
Add jitpack to your repositories.
repositories {
maven("https://jitpack.io")
}
Add the dependency:
implementation("com.github.shaun-wild:KProxy:[version]")
Declare your interface:
interface MyInterface {
val foo: String
}
Create your KInvocationHandler
:
object MyInvocationHandler : KInvocationHandler {
override fun invokeKPropertyRead(proxy: Any?, kProperty: KProperty<*>): Any? {
TODO("Not yet implemented")
}
override fun invokeKPropertyWrite(proxy: Any?, kMutableProperty: KMutableProperty<*>, value: Any?) {
TODO("Not yet implemented")
}
override fun invokeKFunction(proxy: Any?, kFunction: KFunction<*>, args: Array<Any?>): Any? {
TODO("Not yet implemented")
}
}
Create the proxy:
val myProxy = KProxy.newProxyInstance<MyInterface>(MyInvocationHandler)
Now you can use your returned object and the proxy implementation will be used:
println(myProxy.foo)
This project uses Kotlin version 1.6.10
MIT - Give me a shout-out if you like this! 🚀