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
    
    
        }
    
    
    }
  • 相关阅读:
    nyoj 16 矩形嵌套
    nyoj 44 子串和
    nyoj 448 寻找最大数
    nyoj 14 会场安排问题
    hdoj 1008 Elevator
    bzoj1588
    bzoj3224
    bzoj1503
    bzoj1834
    bzoj1066
  • 原文地址:https://www.cnblogs.com/fangyuandoit/p/13713763.html
Copyright © 2011-2022 走看看