mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
b17cd4abb1
commit
b3ddbcba23
@ -5,7 +5,6 @@ import cn.hutool.core.annotation.PropIgnore;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.func.LambdaUtil;
|
||||
import cn.hutool.core.reflect.FieldUtil;
|
||||
import cn.hutool.core.reflect.MethodUtil;
|
||||
import cn.hutool.core.reflect.ModifierUtil;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.core.reflect.TypeUtil;
|
||||
@ -226,8 +225,8 @@ public class PropDesc {
|
||||
*/
|
||||
public PropDesc setValue(final Object bean, final Object value) {
|
||||
if (null != this.setter) {
|
||||
MethodUtil.invoke(bean, this.setter, value);
|
||||
//LambdaUtil.buildSetter(this.setter).accept(bean, value);
|
||||
//MethodUtil.invoke(bean, this.setter, value);
|
||||
LambdaUtil.buildSetter(this.setter).accept(bean, value);
|
||||
} else if (ModifierUtil.isPublic(this.field)) {
|
||||
FieldUtil.setFieldValue(bean, this.field, value);
|
||||
}
|
||||
|
@ -168,7 +168,14 @@ public class LambdaUtil {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, P> BiConsumer<T, P> buildSetter(final Method setMethod) {
|
||||
return LambdaFactory.build(BiConsumer.class, setMethod);
|
||||
final Class<?> returnType = setMethod.getReturnType();
|
||||
if(Void.class == returnType){
|
||||
return LambdaFactory.build(BiConsumer.class, setMethod);
|
||||
}
|
||||
|
||||
// 返回this的setter
|
||||
final BiFunction<T, P, ?> biFunction = LambdaFactory.build(BiFunction.class, setMethod);
|
||||
return biFunction::apply;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,30 @@
|
||||
package cn.hutool.core.bean;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BeanWithReturnThisTest {
|
||||
|
||||
@Test
|
||||
public void setValueTest() {
|
||||
final BeanWithRetuenThis bean = new BeanWithRetuenThis();
|
||||
final BeanDesc beanDesc = BeanUtil.getBeanDesc(BeanWithRetuenThis.class);
|
||||
final PropDesc prop = beanDesc.getProp("a");
|
||||
prop.setValue(bean, "123");
|
||||
|
||||
Assert.assertEquals("123", bean.getA());
|
||||
}
|
||||
|
||||
static class BeanWithRetuenThis{
|
||||
public String getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public BeanWithRetuenThis setA(final String a) {
|
||||
this.a = a;
|
||||
return this;
|
||||
}
|
||||
|
||||
private String a;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user