Easy reflection with Kotlin
- set private and final variables
- syntax comparable to Kotlin Reflect (no dependency to it)
- infix notation available
In Java world there is SuperReflect (a fork of jOOQ/jOOR) for fluent reflection.
Kotlin reflect offers a nice syntax itself but is limited in functionality compared.
KuperReflect combines both worlds: nice syntax including more variations and being able to set private or even final fields.
val myClass = SomeClass()
SomeClass::variable.set(tested, "something")
SomeClass().set(SomeClass::variable).to("something")
SomeClass().set(SomeClass::variable) to "something"
SomeClass().apply {
set(SomeClass::variable) to "something"
}
SomeClass().set("variable").to("something")
SomeClass().set("variable") to "something"
SomeClass().apply {
set("variable") to "something"
}
on(myClass) set "variable" to "something"
on(myClass) set SomeClass::variable to "something"
...
repositories {
maven {url "https://jitpack.io"}
}
testCompile 'com.github.dpreussler:KuperReflect:v0.1'