Skip to content

Instantly share code, notes, and snippets.

@vilmosioo
Created December 5, 2012 18:15
Show Gist options
  • Save vilmosioo/4218094 to your computer and use it in GitHub Desktop.
Save vilmosioo/4218094 to your computer and use it in GitHub Desktop.
Example of reflection usage in Java
protected void setModelProperty(String propertyName, Object newValue) {
for (AbstractModel model : registeredModels) {
try {
Method method = model.getClass().getMethod("set" + propertyName, new Class[] { newValue.getClass() });
method.invoke(model, newValue);
} catch (Exception ex) {
// TODO Handle exception.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment