java中interface是什么意思_java中的接口和@interface有什么区别?

mavis..

102

接口:

通常,接口公开合同而不暴露底层实现细节.在面向对象编程中,接口定义了暴露行为但不包含逻辑的抽象类型.实现由实现接口的类或类型定义.

@interface :(注释类型)

以下面的例子,其中有很多评论:

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:

许多注释取代了代码中的注释.

很好的解释 (9认同)

这实际上很有用.我不知道Java可以做到这一点. (2认同)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值