zoukankan      html  css  js  c++  java
  • 简单的反射

    public class ReflectService {
    
    
        public void sayHi(String name){
            System.out.println("hello"+ name);
        }
    
        public static void main(String[] args)  throws  Exception{
    
           //反射对象
            Class<?> clazz = Class.forName("com.fydemo.demo.reflectdemo.ReflectService");
            ReflectService reflectService = (ReflectService)clazz.newInstance();
            reflectService.sayHi("jj");  //hellojj
    
            //反射方法
            Object clazzService = Class.forName("com.fydemo.demo.reflectdemo.ReflectService").newInstance();
            Method sayHiMethod = clazzService.getClass().getMethod("sayHi", String.class);
            sayHiMethod.invoke(clazzService,"yy");  //helloyy
    
    
        }
    
    
    }
  • 相关阅读:
    LabVIEW入门第三天(软件及驱动包下载)
    poj1732
    poj1722
    poj1821
    poj1770
    poj1949
    poj1726
    poj1699
    poj1682
    poj1853
  • 原文地址:https://www.cnblogs.com/fangyuandoit/p/13713763.html
Copyright © 2011-2022 走看看