java 注解——Annotations Basics
来源:互联网 发布:2016年餐饮业数据分析 编辑:程序博客网 时间:2024/05/16 07:39
// 注解的格式
The Format of an AnnotationIn its simplest form, an annotation looks like the following:
@Entity
// @这个标识符告诉编辑器这是一个注解,下面以重写(Override)这个注解为例
The at sign character (@
) indicates to the compiler that what follows is an annotation. In the following example, the annotation's name is Override
:
@Overridevoid mySuperMethod() { ... }
// 注解可以包括属性(elements),这些属性可以是已命名的也可以的未命名的,而且他们可以有自己的属性值(values)
The annotation can include elements, which can be named or unnamed, and there are values for those elements:
@Author( name = "Benjamin Franklin", date = "3/27/2003")class MyClass() { ... }
or
@SuppressWarnings(value = "unchecked")void myMethod() { ... }
// 如果注解只有一个属性,而且属性名为value,那么属性名可以省略,正像下面这个例子展示的那样
If there is just one element named value
, then the name can be omitted, as in:
@SuppressWarnings("unchecked")void myMethod() { ... }
// 如果注解没有属性,那么括号也可以省略,比如前面@Override的例子
If the annotation has no elements, then the parentheses can be omitted, as shown in the previous @Override
example.
// 同一个位置可以使用多个注解
It is also possible to use multiple annotations on the same declaration:
@Author(name = "Jane Doe")@EBookclass MyClass { ... }
// 如果是多个同类注解,这种情况被称作多重注解
If the annotations have the same type, then this is called a repeating annotation:
@Author(name = "Jane Doe")@Author(name = "John Smith")class MyClass { ... }
// Java SE 8 release 开始支持多重注解,想了解更多,请点击链接
Repeating annotations are supported as of the Java SE 8 release. For more information, see Repeating Annotations.
// 注解可以是Java SE API里面java.lang或者java.lang.annotation这些包里面已经定义的类型,比如前面提到的Override和SuppressWarnings都是
// java预定义注解。也可以是自定义类型,前面例子展示的Author和Ebook都是这一类。
The annotation type can be one of the types that are defined in the java.lang
or java.lang.annotation
packages of the Java SE API. In the previous examples,Override
and SuppressWarnings
are predefined Java annotations. It is also possible to define your own annotation type. The Author
and Ebook
annotations in the previous example are custom annotation types.
- java 注解——Annotations Basics
- Annotations Basics
- Java基础学习——注解(Annotations)学习
- Annotations:注解
- 【jdbc】oracle java tutorial—JDBC Basics
- 黑马程序员---Java注解Annotations的详解以及使用实例
- [JAVA] JDK5.0 Annotations注解hibernate实体类
- Hibernate Annotations 注解
- Hibernate Annotations 中英文注解
- jackson annotations注解详解
- jackson annotations注解详解
- jackson annotations注解详解
- jackson annotations注解详解
- jackson annotations注解详解
- jackson annotations注解详解
- Android Annotations 注解标签
- jackson annotations注解详解
- jackson annotations注解详解
- Python中用format函数格式化字符串
- C语言实验——时间间隔
- leetcode258: Add Digits
- 第八周—兑换钱
- 简单的基于dubbo的调用
- java 注解——Annotations Basics
- 消息称新MacBook暂时不会采用电子墨水键盘
- python学习(3)输入和输出
- Note背后
- 算法一:字符串的模式匹配
- 杀死全部的Activity,退出当前程序
- [Lintcode] Longest Substring Without Repeating Characters 最长无重复字符的子串
- 认识正则表达式
- HTML1