zoukankan      html  css  js  c++  java
  • java-自定义注解

    1 package com.自定义注解;
    2 @TestAnnotation(studentName = "高",id = 31,age = 20)
    3 public class Test {
    4     public static void main(String[] args) {
    5 
    6 
    7     }
    8 }
     1 import java.lang.annotation.ElementType;
     2 import java.lang.annotation.Retention;
     3 import java.lang.annotation.RetentionPolicy;
     4 import java.lang.annotation.Target;
     5 
     6 @Target(value = {ElementType.METHOD,ElementType.TYPE})
     7 @Retention(RetentionPolicy.RUNTIME)
     8 public @interface TestAnnotation {
     9 
    10   String studentName() default "";
    11   int age() default 0;
    12   int id() default -1;
    13 
    14 }
    package com.自定义注解;
    
    public class Test02 {
        //注解中只有一个参数可以吧参数名省略
        @TestAnnotation02("aaa")
       public void test(){
    
       }
    }
     1 package com.自定义注解;
     2 
     3 import java.lang.annotation.ElementType;
     4 import java.lang.annotation.Retention;
     5 import java.lang.annotation.RetentionPolicy;
     6 import java.lang.annotation.Target;
     7 
     8 @Target(value = {ElementType.METHOD,ElementType.TYPE})
     9 @Retention(RetentionPolicy.RUNTIME)
    10 public @interface TestAnnotation02 {
    11     String value();//注解里面只有一个参数就把他的参数名定为value.但是定义为别的也可以一般这么定义
    12 }
  • 相关阅读:
    linux 安全组
    php 类
    linux安装phpmyadmin
    mysql设置对外访问
    linux 防火墙
    微信小程序之swiper组件高度自适应
    Thinkphp5 关联模型
    README.md文件编辑
    linux安装mysql
    小程序返回顶部top滚动
  • 原文地址:https://www.cnblogs.com/xiaoqiqistudy/p/11017335.html
Copyright © 2011-2022 走看看