zoukankan      html  css  js  c++  java
  • Java 注解 反射

    注解:Java.lang.annotation;

    1.定义: public @interface 注解名{String value(); int age();int id() default ""};

    2.编译器中注解:@Override  @Deprecated  @SuppressWarnings   @Target( ElementType={ })  @Rentation(RentationPolicy={}) @Documented @Inherited

    3. 自定义注解 @interface test{         }

    反射:java.lang.reflection   java.lang.Class     (Pojo  属性  set/get   无参构造,  toString())

    1.反射机制:获取类的任何内部信息,直接操作属性和方法。 

    2.Class类和获取Class类实例 :  类.Class    对象.getClass()  Class.forName("  ") Integer.Type   类.class.getSuperClass();

                    1.Class 本身也是一个类

                    2.Class对象只能有系统建立对象

                    3.一个加载的类在JVM中只会有一个Class实例

                    4.一个Class对象对应的事一个加载到JVM里的一个.class文件

                    5.每个类的实例都会记得自己是由哪个Class实例所生成的。

                    6.通过Class可以完整的得到一个类中的所有被加载的结构

                    7.Class类的Reflection的根源,针对任何你想动态加载、运行的类,唯有先获得相应的Class对象。

    3.类的加载与ClassLoader

           1.加载.class 文件  2.验证:class文件是否符合jvm规范;准备:static,类变量 分配内存;解析:

      3.初始化:《clint》

       ClassLoader.getSystemclassloader();

            System.getProperty("java.class.path")

        根加载器null ----->   扩展类加载器  -------->   系统类加载器

    4.创建运行时类的对象

          Class 

       getName() 

       getSimpleName() 

        getFields()    getDeclaredFields()

        getMehtods()  getDeclaredMthods()   getMethod("方法名","参数类型.class")

      getConstruct()

        newInstance()

        属性和方法都有setAcessible(true)

    5.获取运行时类的完整结构

     f= Class . getAnotation(注解.class)     f.value();

      Field .getAnnotation(注解.class)      

    6.调用运行时类的指定结构

  • 相关阅读:
    php生成随机颜色代码
    终于完成了 源码 编译lnmp环境
    json_encode 中文 null
    push is not a function
    linux 搭建svn 服务器
    samba 挂载windows共享文件夹
    php 加密 解密 方法
    serialize unserialize
    CentOS Linux解决Device eth0 does not seem to be present 但是没有发现eth1
    javascript 获取视口的高度和宽度
  • 原文地址:https://www.cnblogs.com/chencn/p/12234363.html
Copyright © 2011-2022 走看看