问题描述
当我注意到它是一个'静态'界面时,我正在阅读Map.Entry界面。我不太明白静态接口是什么,它与常规接口有什么不同?
I was reading through the Map.Entry interface, when I noticed it is a 'static' interface. I didn't quite understand what a static interface is, and how is it different from a regular interface ?
public static interface Map.Entry< K,V>
这是界面的定义。文档:
This is the definition of the interface. Docs here: http://docs.oracle.com/javase/6/docs/api/java/util/Map.Entry.html
推荐答案
static
仅允许在嵌套类或接口上使用修饰符。在您的示例中,条目
嵌套在 Map
界面内。
The static
modifier is only allowed on a nested classes or interfaces. In your example Entry
is nested inside the Map
interface.
对于接口, static
修饰符实际上是可选的。这种区别对接口毫无意义,因为它们不包含任何可以访问外部此
的代码。
For interfaces, the static
modifier is actually optional. The distinction makes no sense for interfaces since they contain no code that could access the outer this
anyway.
这篇关于什么是java中的静态接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!