Advertisement
Guest User

Untitled

a guest
May 31st, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. package reflaction;
  2.  
  3. import java.lang.reflect.InvocationTargetException;
  4. import java.lang.reflect.Method;
  5. import java.util.Map;
  6.  
  7. /**
  8. * Created by BJJ on 31.05.2016.
  9. */
  10. public class Reflect<T> {
  11.  
  12.  
  13. public T initClass(Class<T> tClass, Map<String, Object> map) throws IllegalAccessException, InstantiationException, InvocationTargetException {
  14. T oClass = tClass.newInstance();
  15.  
  16. Method[] methods = oClass.getClass().getDeclaredMethods();
  17. for (Map.Entry<String, Object> entry : map.entrySet()) {
  18. for (Method method : methods) {
  19.  
  20. if (method.getName().equalsIgnoreCase("set" + entry.getKey())) {
  21. method.invoke(oClass, entry.getValue());
  22. }
  23. }
  24. }
  25.  
  26. return oClass;
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement