码迷,mamicode.com
首页 > 编程语言 > 详细

Java注解学习

时间:2017-06-26 22:35:17      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:3.0   test   single   marker   hello   学习   double   ann   war   

Java提供了特定的注解(比较基础的例如:Override、Deprecated、SuppressWarnings)。

自定义注解:

有三种:

普通注解:

public @interface aAnnotation {
    String value();
    int i();
    float f() default 2.0f;
    double d();
}

public class AnnotationTester {
    @aAnnotation(value = "hello", i = 1, f = 2.0f, d = 3.0)
    public void Method()
    {
    }
}

标记注解:

public @interface MarkerAnnotation {
}

public class AnnotationTester {
    @MarkerAnnotation
    public void Method()
    {
    }
}

单值注解:

public @interface SingleValueAnnotation {
    String value();
}

public class AnnotationTester {
    @SingleValueAnnotation("hello")
    public void Method()
    {
    }
}

Java注解学习

标签:3.0   test   single   marker   hello   学习   double   ann   war   

原文地址:http://www.cnblogs.com/quanxi/p/7082530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!