BeanUtils not works for chain setter

后端 未结 3 962
你的背包
你的背包 2021-01-04 19:25

e.g.

class tester
{
    @Test
    public void testBeanUtils() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        S         


        
3条回答
  •  别那么骄傲
    2021-01-04 20:27

    That's simple: BeanUtils are rather strange and so is Introspector it uses:

    Although BeanUtils.setProperty declares some exceptions, it seems to silently ignore the non-existence of the property to be set. The ultimate culprit is the Introspector which simply requires the voidness of setter.

    I'd call it broken by design, but YMMV. It's an old class and fluent interfaces weren't invented yet in those dark times. Use Accessors(chain=false) to disable chaining.


    More important: Use the source. Get it and get a debugger (it's already in your IDE) to find it out yourself (still feel free to ask if it doesn't work, just try a bit harder).

提交回复
热议问题