mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-05 18:25:28 +08:00
Modify add argument generics method in GenericClass
This commit is contained in:
@@ -30,10 +30,18 @@ class GenericClass internal constructor(private val type: ParameterizedType)
|
|||||||
fun argument(index: Int): Class<*>
|
fun argument(index: Int): Class<*>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```kotlin:no-line-numbers
|
||||||
|
inline fun <reified T> argument(index: Int): Class<T>
|
||||||
|
```
|
||||||
|
|
||||||
**Change Records**
|
**Change Records**
|
||||||
|
|
||||||
`v1.1.0` `added`
|
`v1.1.0` `added`
|
||||||
|
|
||||||
|
`v1.1.5` `modified`
|
||||||
|
|
||||||
|
新增泛型返回值 `Class<T>` 方法
|
||||||
|
|
||||||
**Function Illustrate**
|
**Function Illustrate**
|
||||||
|
|
||||||
> 获得泛型参数数组下标的 `Class` 实例。
|
> 获得泛型参数数组下标的 `Class` 实例。
|
@@ -22,10 +22,18 @@ class GenericClass internal constructor(private val type: ParameterizedType)
|
|||||||
fun argument(index: Int): Class<*>
|
fun argument(index: Int): Class<*>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```kotlin:no-line-numbers
|
||||||
|
inline fun <reified T> argument(index: Int): Class<T>
|
||||||
|
```
|
||||||
|
|
||||||
**变更记录**
|
**变更记录**
|
||||||
|
|
||||||
`v1.1.0` `新增`
|
`v1.1.0` `新增`
|
||||||
|
|
||||||
|
`v1.1.5` `修改`
|
||||||
|
|
||||||
|
新增泛型返回值 `Class<T>` 方法
|
||||||
|
|
||||||
**功能描述**
|
**功能描述**
|
||||||
|
|
||||||
> 获得泛型参数数组下标的 `Class` 实例。
|
> 获得泛型参数数组下标的 `Class` 实例。
|
@@ -25,7 +25,7 @@
|
|||||||
*
|
*
|
||||||
* This file is Created by fankes on 2022/9/20.
|
* This file is Created by fankes on 2022/9/20.
|
||||||
*/
|
*/
|
||||||
@file:Suppress("unused")
|
@file:Suppress("unused", "UNCHECKED_CAST")
|
||||||
|
|
||||||
package com.highcapable.yukihookapi.hook.bean
|
package com.highcapable.yukihookapi.hook.bean
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ import java.lang.reflect.ParameterizedType
|
|||||||
* 当前 [Class] 的泛型父类操作对象
|
* 当前 [Class] 的泛型父类操作对象
|
||||||
* @param type 类型声明实例
|
* @param type 类型声明实例
|
||||||
*/
|
*/
|
||||||
class GenericClass internal constructor(private val type: ParameterizedType) {
|
class GenericClass internal constructor(@PublishedApi internal val type: ParameterizedType) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得泛型参数数组下标的 [Class] 实例
|
* 获得泛型参数数组下标的 [Class] 实例
|
||||||
@@ -43,4 +43,14 @@ class GenericClass internal constructor(private val type: ParameterizedType) {
|
|||||||
* @return [Class]
|
* @return [Class]
|
||||||
*/
|
*/
|
||||||
fun argument(index: Int = 0) = type.actualTypeArguments[index] as Class<*>
|
fun argument(index: Int = 0) = type.actualTypeArguments[index] as Class<*>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得泛型参数数组下标的 [Class] 实例
|
||||||
|
* @param index 数组下标 - 默认 0
|
||||||
|
* @return [Class]<[T]>
|
||||||
|
* @throws IllegalStateException 如果 [Class] 的类型不为 [T]
|
||||||
|
*/
|
||||||
|
@JvmName("argument_Generics")
|
||||||
|
inline fun <reified T> argument(index: Int = 0) =
|
||||||
|
type.actualTypeArguments[index] as? Class<T> ?: error("Target Class type cannot cast to ${T::class.java}")
|
||||||
}
|
}
|
Reference in New Issue
Block a user