zoukankan      html  css  js  c++  java
  • java中反射的理解

    记录是为了更好的成长!

    1、java加载class的三种方式

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
            //加载类的三种方式
            //1、使用new关键字方法
            User user = new User();
            Method[] methods = user.getClass().getDeclaredMethods();
            for(Method method:methods) {
                System.out.println(method);
            }
            
            //2、调用 Class.forName() 方法
            Class clazz= Class.forName("com.boot.test.User");
            Object user1 = clazz.newInstance();
            Method[] methods1 = user1.getClass().getDeclaredMethods();
            System.out.println(" Class.forName()+++++++++++++++++++++++++++++++");
            for(Method method:methods1) {
                System.out.println(method);
            }
            
            //3、调用某个 ClassLoader 实例的 loadClass() 方法
            Class clazz1 = ClassLoader.getSystemClassLoader().loadClass("com.boot.test.User");
            Method[] methods2 = clazz1.getClass().getDeclaredMethods();
            System.out.println(" loadClass()+++++++++++++++++++++++++++++++");
            for(Method method:methods2) {
                System.out.println(method);
            }    
        }

    以上内容代表个人观点,仅供参考,不喜勿喷。。。

  • 相关阅读:
    Fiddler抓包整理
    redis集群
    php性能加速:Opcache
    细说一下position(定位),以及其他的小知识
    css的小知识3
    css小知识 2
    网页背景的属性及使用
    css小知识
    属性的特征和一些选择器的使用
    浏览器介绍和一些简单的代码
  • 原文地址:https://www.cnblogs.com/newbest/p/10054101.html
Copyright © 2011-2022 走看看