문제

Does Beanutils or any associated classes provide a method to populate a readonly property like the example below?

class MyBean {
    private String check;

    public String getCheck() {
        return check;
    }

    @SuppressWarnings("unused")
    private void setCheck(String check) {
        this.check = check;
    }
}

Thanks for your help

도움이 되었습니까?

해결책

Sorry for posting this question actually this can be achieved using reflection and not beanUtils,

    MyBean bean = new MyBean();
        Class<?> c = bean.getClass();
        Field f = c.getDeclaredField("id");
        f.setAccessible(true);
        f.set(bean, 12346l);            

This is what i was looking for.

Vaibhav

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top