Created
December 5, 2012 18:15
-
-
Save vilmosioo/4218094 to your computer and use it in GitHub Desktop.
Example of reflection usage in Java
This file contains 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
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