在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):wuseal/Kotlin-Reflect-Tools-For-Android开源软件地址(OpenSource Url):https://github.com/wuseal/Kotlin-Reflect-Tools-For-Android开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):Kotlin-Reflect-Tools-For-AndroidKotlin reflect tools for Android Related Project: Kotlin-Reflect-Tools-For-JVM OverViewThis is a tool library for Kotlin to use java reflect APIs in Kotlin simply method on android platform. It can modify or read the top level private visible property value in Kotlin way. Usage
APIs
All method don't care what the property or method visibility it is DemoFor example a Kotlin file like this: val topName = "topSeal"
val topNameWu = "topSealWu"
private val topAge = 666
private fun gotIt() = true
fun funDoubleAge(age: Int): Int {
return age * 2
}
class TestDemo {
private val name = "seal"
val age = 28
private fun isMan(): Boolean {
return true
}
} Then we could do these :
@Test
fun getPropertyValue() {
val demo = TestDemo()
val nameValue = demo.getPropertyValue("name")
nameValue.should.be.equal("seal")
}
@Test
fun changePropertyValue() {
val demo = TestDemo()
val originValue = demo.age
demo.changePropertyValue("age", 100)
val nowValue = demo.age
originValue.should.not.equal(nowValue)
nowValue.should.be.equal(100)
}
@Test
fun changeValue() {
val demo = TestDemo()
demo::age.changeValue(demo, 100)
demo.age.should.be.equal(100)
}
@Test
fun packageLevelGetPropertyValueByName() {
val topAge = ::topNameWu.packageLevelGetPropertyValueByName("topAge")
topAge.should.be.equal(666)
}
@Test
fun packageLevelInvokeMethodByName() {
val methodResult = ::topName.packageLevelInvokeMethodByName("gotIt") as Boolean
methodResult.should.be.`true`
}
To see more usage cases ,you can have a look at the AndroidTest case in project. Others
Find me useful ? |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论