Skip to content

Instantly share code, notes, and snippets.

@timaschew
Created September 20, 2011 13:29
Show Gist options
  • Save timaschew/1229063 to your computer and use it in GitHub Desktop.
Save timaschew/1229063 to your computer and use it in GitHub Desktop.
Field[] fields = MaxLearnIterationsStrategy.class.getDeclaredFields();
for (Field f : fields) {
Class<?> type = f.getType();
System.out.println(f.getName() + " / " + type.getSimpleName());
try {
Class cls = Class.forName(MaxLearnIterationsStrategy.class.getName());
Field fld = cls.getField(f.getName());
fld.setAccessible(true);
Object obj = cls.newInstance();
if (f.getType().equals(Integer.class)) {
fld.setDouble(obj, 12);
} else if (f.getType().equals(Double.class)) {
fld.setDouble(obj, 12.34);
} else {
System.err.println("type not supported: " + f.getType());
}
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment