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 }
  • 相关阅读:
    mysql复制那点事
    全排列问题
    56. Merge Interval
    2. Add Two Numbers
    20. Valid Parentheses
    121. Best Time to Buy and Sell Stock
    120. Triangle
    96. Unique Binary Search Trees
    91. Decode Ways
    72. Edit Distance
  • 原文地址:https://www.cnblogs.com/xiaoqiqistudy/p/11017335.html
Copyright © 2011-2022 走看看