mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
aae583e57f
commit
5f1b010d08
@ -163,6 +163,7 @@ public class LookupUtil {
|
|||||||
|
|
||||||
MethodHandle handle = null;
|
MethodHandle handle = null;
|
||||||
final MethodHandles.Lookup lookup = LookupUtil.lookup(callerClass);
|
final MethodHandles.Lookup lookup = LookupUtil.lookup(callerClass);
|
||||||
|
// 成员方法
|
||||||
try {
|
try {
|
||||||
handle = lookup.findVirtual(callerClass, name, type);
|
handle = lookup.findVirtual(callerClass, name, type);
|
||||||
} catch (final IllegalAccessException | NoSuchMethodException ignore) {
|
} catch (final IllegalAccessException | NoSuchMethodException ignore) {
|
||||||
|
@ -18,7 +18,6 @@ import org.dromara.hutool.core.lang.Assert;
|
|||||||
import org.dromara.hutool.core.reflect.lookup.LookupUtil;
|
import org.dromara.hutool.core.reflect.lookup.LookupUtil;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,6 +41,12 @@ public class MethodHandleUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行方法句柄,{@link MethodHandle#invokeWithArguments(Object...)}包装<br>
|
* 执行方法句柄,{@link MethodHandle#invokeWithArguments(Object...)}包装<br>
|
||||||
|
* 非static方法需先调用{@link MethodHandle#bindTo(Object)}绑定执行对象。
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 需要注意的是,此处没有使用{@link MethodHandle#invoke(Object...)},因为其参数第一个必须为对象或类。<br>
|
||||||
|
* {@link MethodHandle#invokeWithArguments(Object...)}只需传参数即可。
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param methodHandle {@link MethodHandle}
|
* @param methodHandle {@link MethodHandle}
|
||||||
* @param args 方法参数值,支持子类转换和自动拆装箱
|
* @param args 方法参数值,支持子类转换和自动拆装箱
|
||||||
@ -118,24 +123,6 @@ public class MethodHandleUtil {
|
|||||||
if (null != obj) {
|
if (null != obj) {
|
||||||
handle = handle.bindTo(obj);
|
handle = handle.bindTo(obj);
|
||||||
}
|
}
|
||||||
return invokeWithArguments(handle, args);
|
return invokeHandle(handle, args);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行方法句柄,{@link MethodHandle#invokeWithArguments(Object...)}包装<br>
|
|
||||||
*
|
|
||||||
* @param handle {@link MethodHandle}
|
|
||||||
* @param args 方法参数值,支持子类转换和自动拆装箱
|
|
||||||
* @param <T> 返回值类型
|
|
||||||
* @return 方法返回值
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T invokeWithArguments(final MethodHandle handle, final Object... args){
|
|
||||||
Assert.notNull(handle, "MethodHandle must be not null!");
|
|
||||||
try {
|
|
||||||
return (T) handle.invokeWithArguments(args);
|
|
||||||
} catch (final Throwable e) {
|
|
||||||
throw ExceptionUtil.wrapRuntime(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user