java 开发过程,各种各样的注解

  • @Retention

    Retention(保留)注解说明,这种类型的注解会被保留到那个阶段. 有三个值: 1.RetentionPolicy.SOURCE —— 这种类型的Annotations只在源代码级别保留,编译时就会被忽略 2.RetentionPolicy.CLASS —— 这种类型的Annotations编译时被保留,在class文件中存在,但JVM将会忽略 3.RetentionPolicy.RUNTIME —— 这种类型的Annotations将被JVM保留,所以他们能在运行时被JVM或其他使用反射机制的代码所读取和使用.

  • @Inherited

    允许子类继承父类注解,如 @Target(ElementType.TYPE)   @Retention(RetentionPolicy.RUNTIME)   @Inherited   public @interface TypeParent {        public String say() default "";       }  

    ///////////////////////////////////////// @TypeParent public class Typechild{     public String move(){}     public String eat(){} }

上面中Typechild加了@TypeParent注解,那么他会继承自TypeParent,当然会拥有say()方法。

  • @Target 注解的作用目标

    @Target(ElementType.TYPE)   //接口、类、枚举、注解 @Target(ElementType.FIELD) //字段、枚举的常量 @Target(ElementType.METHOD) //方法 @Target(ElementType.PARAMETER) //方法参数 @Target(ElementType.CONSTRUCTOR)  //构造函数 @Target(ElementType.LOCAL_VARIABLE)//局部变量 @Target(ElementType.ANNOTATION_TYPE)//注解 @Target(ElementType.PACKAGE) ///包

  • @Document

表示该对象能出现在javadoc中,运行命令后。

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0