Created
September 20, 2011 13:29
-
-
Save timaschew/1229063 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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