什么是java中的静态接口? [英] what is a static interface in java?

查看:792
本文介绍了什么是java中的静态接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我注意到它是一个'静态'界面时,我正在阅读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>

这是界面的定义。文档: http://docs.oracle。 com / javase / 6 / docs / api / java / util / Map.Entry.html

This is the definition of the interface. Docs here: http://docs.oracle.com/javase/6/docs/api/java/util/Map.Entry.html

推荐答案


当它不是内部接口时,我很好奇。

I'm curious about the case when it's not an inner interface.

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中的静态接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆