zoukankan      html  css  js  c++  java
  • 反射

     
    3
    4
    5
    6
    7
    8
    package net.xsoftlab.baike;
    public class TestReflect {
        public static void main(String[] args) throws Exception {
            TestReflect testReflect = new TestReflect();
            System.out.println(testReflect.getClass().getName());
            // 结果 net.xsoftlab.baike.TestReflect
        }
    }
    package net.xsoftlab.baike;
    public class TestReflect {
        public static void main(String[] args) throws Exception {
            Class<?> class1 = null;
            Class<?> class2 = null;
            Class<?> class3 = null;
            // 一般采用这种形式
            class1 = Class.forName("net.xsoftlab.baike.TestReflect");
            class2 = new TestReflect().getClass();
            class3 = TestReflect.class;
            System.out.println("类名称   " + class1.getName());
            System.out.println("类名称   " + class2.getName());
            System.out.println("类名称   " + class3.getName());
        }
    }
     
     
    package net.xsoftlab.baike;
    import java.io.Serializable;
    public class TestReflect implements Serializable {
        private static final long serialVersionUID = -2862585049955236662L;
        public static void main(String[] args) throws Exception {
            Class<?> clazz = Class.forName("net.xsoftlab.baike.TestReflect");
            // 取得父类
            Class<?> parentClass = clazz.getSuperclass();
            System.out.println("clazz的父类为:" + parentClass.getName());
            // clazz的父类为: java.lang.Object
            // 获取所有的接口
            Class<?> intes[] = clazz.getInterfaces();
            System.out.println("clazz实现的接口有:");
            for (int i = 0; i < intes.length; i++) {
                System.out.println((i + 1) + ":" + intes[i].getName());
            }
            // clazz实现的接口有:
            // 1:java.io.Serializable
        }
    }
     
     
     
     
     
     
     
  • 相关阅读:
    IL汇编语言介绍(译)
    开源搜索框架Lucene学习系列
    【转】autoHeight为true的时候,autoScroll为true就不起作用了
    [转]反注册 Regsvr32命令应用大全
    [转]sun.misc.BASE64Encoder找不到的解决方法
    mysql数据库导入导出
    【转】MySQL 与MS SQL Server数据库使用多表关联Update时语法的区别
    CRT detected that the application wrote to memory after end of heap buffer
    魔兽争霸窗口化
    GROUP_CONCAT函数
  • 原文地址:https://www.cnblogs.com/with-lj/p/7678733.html
Copyright © 2011-2022 走看看