mirror of
https://github.com/HighCapable/KavaRef.git
synced 2025-10-18 13:19:21 +08:00
style: update demo
This commit is contained in:
@@ -30,12 +30,14 @@ import com.highcapable.kavaref.runtime.KavaRefRuntime
|
|||||||
fun main() {
|
fun main() {
|
||||||
// Enable KavaRef debug level logging.
|
// Enable KavaRef debug level logging.
|
||||||
KavaRef.logLevel = KavaRefRuntime.LogLevel.DEBUG
|
KavaRef.logLevel = KavaRefRuntime.LogLevel.DEBUG
|
||||||
|
|
||||||
// Resolve the Test class using KavaRef.
|
// Resolve the Test class using KavaRef.
|
||||||
// Create an instance of the Test class using the resolved class.
|
// Create an instance of the Test class using the resolved class.
|
||||||
val test = Test::class.resolve()
|
val test = Test::class.resolve()
|
||||||
.firstConstructor {
|
.firstConstructor {
|
||||||
emptyParameters()
|
emptyParameters()
|
||||||
}.create()
|
}.create()
|
||||||
|
|
||||||
// Invoke a method, modify a field, and retrieve a value using the resolved class.
|
// Invoke a method, modify a field, and retrieve a value using the resolved class.
|
||||||
// (1) Call from Class.
|
// (1) Call from Class.
|
||||||
Test::class.resolve()
|
Test::class.resolve()
|
||||||
@@ -43,12 +45,14 @@ fun main() {
|
|||||||
name = "test"
|
name = "test"
|
||||||
parameters(String::class)
|
parameters(String::class)
|
||||||
}.of(test).invoke("reflection test")
|
}.of(test).invoke("reflection test")
|
||||||
|
|
||||||
// (2) Call from Object.
|
// (2) Call from Object.
|
||||||
test.asResolver()
|
test.asResolver()
|
||||||
.firstMethod {
|
.firstMethod {
|
||||||
name = "test"
|
name = "test"
|
||||||
parameters(String::class)
|
parameters(String::class)
|
||||||
}.invoke("reflection test")
|
}.invoke("reflection test")
|
||||||
|
|
||||||
// Modify the field 'myTest' and retrieve its value using the resolved class.
|
// Modify the field 'myTest' and retrieve its value using the resolved class.
|
||||||
// (1) Call from Class.
|
// (1) Call from Class.
|
||||||
Test::class.resolve()
|
Test::class.resolve()
|
||||||
@@ -56,12 +60,14 @@ fun main() {
|
|||||||
name = "myTest"
|
name = "myTest"
|
||||||
type = String::class
|
type = String::class
|
||||||
}.of(test).set("Hello modified reflection test")
|
}.of(test).set("Hello modified reflection test")
|
||||||
|
|
||||||
// (2) Call from Object.
|
// (2) Call from Object.
|
||||||
test.asResolver()
|
test.asResolver()
|
||||||
.firstField {
|
.firstField {
|
||||||
name = "myTest"
|
name = "myTest"
|
||||||
type = String::class
|
type = String::class
|
||||||
}.set("Hello modified reflection test")
|
}.set("Hello modified reflection test")
|
||||||
|
|
||||||
// Retrieve the value of the field 'myTest' using the resolved class.
|
// Retrieve the value of the field 'myTest' using the resolved class.
|
||||||
// (1) Call from Class.
|
// (1) Call from Class.
|
||||||
val testString1 = Test::class.resolve()
|
val testString1 = Test::class.resolve()
|
||||||
@@ -69,12 +75,14 @@ fun main() {
|
|||||||
name = "getTest"
|
name = "getTest"
|
||||||
emptyParameters()
|
emptyParameters()
|
||||||
}.of(test).invoke<String>()
|
}.of(test).invoke<String>()
|
||||||
|
|
||||||
// (2) Call from Object.
|
// (2) Call from Object.
|
||||||
val testString2 = test.asResolver()
|
val testString2 = test.asResolver()
|
||||||
.firstMethod {
|
.firstMethod {
|
||||||
name = "getTest"
|
name = "getTest"
|
||||||
emptyParameters()
|
emptyParameters()
|
||||||
}.invoke<String>()
|
}.invoke<String>()
|
||||||
|
|
||||||
// Print the value of the field 'myTest'.
|
// Print the value of the field 'myTest'.
|
||||||
println(testString1)
|
println(testString1)
|
||||||
println(testString2)
|
println(testString2)
|
||||||
|
Reference in New Issue
Block a user