Last active
February 21, 2016 20:28
-
-
Save AnnaBoro/6d2d0930b2f0f2706d0a to your computer and use it in GitHub Desktop.
initClass
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
package lesson7_10.reflection; | |
import java.lang.reflect.Field; | |
import java.util.Map; | |
public class Reflection2<T> { | |
public T initClass(Class<T> tClass, Map<String, Object> map) throws IllegalAccessException, InstantiationException, InvocationTargetException { | |
T oClass = tClass.newInstance(); | |
Method[] methods = oClass.getClass().getDeclaredMethods(); | |
for (Map.Entry<String, Object> entry : map.entrySet()) { | |
for (Method method : methods) { | |
if (method.getName().equalsIgnoreCase("set" + entry.getKey())) { | |
method.invoke(oClass, entry.getValue()); | |
} | |
} | |
} | |
return oClass; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment