Close

Spring Framework - DirectFieldAccessor Examples

Spring Framework 

DirectFieldAccessor can be used to read and write fields without setters and getters.

package com.logicbig.example.directfieldAccessor;

import org.springframework.beans.DirectFieldAccessor;

public class DirectFieldAccessorExample {

public static void main (String[] args) {
DirectFieldAccessor a = new DirectFieldAccessor(new LocalBean());
a.setPropertyValue("str", "setting a direct value");
System.out.println(a.getWrappedInstance());
}

private static class LocalBean {
private String str;

@Override
public String toString () {
return "LocalBean{" +
"str='" + str + '\'' +
'}';
}
}
}

Output

LocalBean{str='setting a direct value'}
Original Post




See Also