public
class
Bean {
public
static
final
String dbtype=
new
String();
}
public
static
void
changFinalProperty(Class clazz ,Object newvalue)
{
try
{
Object o = clazz.newInstance();
Field field = clazz.getDeclaredField(
"dbtype"
);
field.setAccessible(
true
);
Field modifiersField = Field.
class
.getDeclaredField(
"modifiers"
);
modifiersField.setAccessible(
true
);
modifiersField.set(field, field.getModifiers() & ~Modifier.FINAL);
field.set(
null
, newvalue);
}
catch
(NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch
(SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch
(IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch
(IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch
(InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Bean.dbtype);
}