Java examples for Reflection:Java Bean
set Java Bean Property Value
//package com.java2s; import java.lang.reflect.Field; public class Main { public static void setValue(String field, Object bean, Object value) { try {/*from ww w . j ava2 s . co m*/ Field f = bean.getClass().getDeclaredField(field); boolean b = f.isAccessible(); f.setAccessible(true); f.set(bean, value); f.setAccessible(b); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } } }