Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package reflaction;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- import java.util.Map;
- /**
- * Created by BJJ on 31.05.2016.
- */
- public class Reflect<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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement