接口:
一般而言,接口暴露而不暴露下面的实施细节的合同。在面向对象编程中,接口定义暴露行为的抽象类型,但不包含逻辑。实现由实现接口的类或类型定义。
@interface:(Annotation类型)
以下面的例子,里面有很多的评论:
public class Generation3List extends Generation2List {
// Author: John Doe
// Date: 3/17/2002
// Current revision: 6
// Last modified: 4/12/2004
// By: Jane Doe
// Reviewers: Alice, Bill, Cindy
// class code goes here
}
取而代之的是,你可以声明注释类型
@interface ClassPreamble {
String author();
String date();
int currentRevision() default 1;
String lastModified() default "N/A";
String lastModifiedBy() default "N/A";
// Note use of array
String[] reviewers();
}
然后可以如下注释一个类:
@ClassPreamble (
author = "John Doe",
date = "3/17/2002",
currentRevision = 6,
lastModified = "4/12/2004",
lastModifiedBy = "Jane Doe",
// Note array notation
reviewers = {"Alice", "Bob", "Cindy"}
)
public class Generation3List extends Generation2List {
// class code goes here
}
PS: 许多注释代码中的注释。
参考:http://docs.oracle.com/javase/tutorial/java/annotations/declaring.html
十分感谢,好知道。那么称它为@interface的理由是什么,而不是@annotation我想知道..似乎是一个不必要的重载术语。 – Bittercoder 2009-05-27 23:46:00
本教程和JLS暗示注解是一种特殊的界面。关于这个主题似乎没有太多讨论,但http://javarunner.blogspot.com/2005/01/annotations-in-java-15.html解释说明注释是Annotation接口的隐式扩展和@和界面用于共同区分常规界面。您可能还想阅读JSR规范的注释。 – DavidValeri 2009-05-28 11:41:32