docs: update features

This commit is contained in:
2023-10-06 02:20:55 +08:00
parent 7aea96f3fc
commit 98a0c212de
2 changed files with 90 additions and 0 deletions

View File

@@ -70,6 +70,52 @@ For more functions, please refer to [classOf](../api/public/com/highcapable/yuki
:::
### Lazy Loading
Suppose we want to get a `Class` that cannot be called directly, but we do not need this `Class` immediately.
At this time, you can use `lazyClass` to complete this function.
> The following example
```kotlin
// Lazy loading of this Class
val instance by lazyClass("com.demo.Test")
// Customize the ClassLoader where the Class is located
val customClassLoader: ClassLoader? = ... // Assume this is your ClassLoader
val instance by lazyClass("com.demo.Test") { customClassLoader }
// Call this Class at the appropriate time
instance.method {
// ...
}
```
If the current `Class` does not exist, using the above method will throw an exception.
If you are not sure whether `Class` exists, you can refer to the following solution.
> The following example
```kotlin
// Lazy loading of this Class
// If not available, the result will be null but no exception will be thrown
val instance by lazyClassOrNull("com.demo.Test")
// Customize the ClassLoader where the Class is located
val customClassLoader: ClassLoader? = ... // Assume this is your ClassLoader
// If not available, the result will be null but no exception will be thrown
val instance by lazyClassOrNull("com.demo.Test") { customClassLoader }
// Call this Class at the appropriate time
instance?.method {
// ...
}
```
::: tip
For more functions, please refer to [lazyClass](../public/com/highcapable/yukireflection/factory/ReflectionFactory#lazyclass-method), [lazyClassOrNull](../public/com/highcapable/yukireflection/factory/ReflectionFactory#lazyclassornull-method) methods.
:::
### Existential Judgment
Suppose we want to determine whether a `Class` exists.