zoukankan      html  css  js  c++  java
  • 泛型与反射的使用

    package com.yonyou.cyxdms.retail.service.service.manufacturerorders;

    import com.yonyou.cyxdms.retail.service.entity.vo.salesorders.manufactuer.Test001;
    import com.yonyou.cyxdms.retail.service.entity.vo.salesorders.manufactuer.Test002;

    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;

    public class test {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Test001 test001 = new Test001();
    test001.setA("10086");
    test001.setB("10010");
    Test002 test002 = new Test002();
    getOO(test002,test001);
    System.out.println(test002.getA() + "---" + test002.getB());
    }

    private static void getOO(Object object,Object dateVO) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Class<?> aClass = object.getClass();
    Class<?> dataClass = dateVO.getClass();
    Method[] declaredMethods = aClass.getDeclaredMethods();
    for (Method method : declaredMethods) {
    // set
    if (method.getName().startsWith("set")){
    Method method1 = dataClass.getMethod("get" + method.getName().substring(3));
    Object invoke = method1.invoke(dateVO);
    method.invoke(object, invoke);
    }
    }
    }
    }
    返回值

    10086---10010



  • 相关阅读:
    【BZOJ2287】消失之物
    【NOI2001】炮兵阵地
    【SCOI2005】互不侵犯
    【USACO2007 nov glod】玉米田
    【NOIP模拟】航班
    【NOIP模拟】闲荡
    【NOIP模拟】军队调遣
    树形地铁系统
    矩阵
    完美的集合(题解)
  • 原文地址:https://www.cnblogs.com/jabez1992/p/13187870.html
Copyright © 2011-2022 走看看