Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top