Suppose you have a text file like:
my_setting = ON some_method = METHOD_A verbosity = DEBUG ...
That you wish to to update a corresponding
Alternative solution with no casting
try { Method valueOf = field.getType().getMethod("valueOf", String.class); Object value = valueOf.invoke(null, param); field.set(test, value); } catch ( ReflectiveOperationException e) { // handle error here }