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

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

问题描述

我正在阅读 Map.Entry 接口,当我注意到它是一个 static 接口时.我不太明白什么是静态接口,它和普通接口有什么区别?

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>

这是接口的定义.文档在这里:Map.Entry<K,V>.

This is the definition of the interface. Docs here: Map.Entry<K,V>.

推荐答案

我对不是内部接口的情况很好奇.

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

static 修饰符只允许用于嵌套的类或接口.在您的示例中,Entry 嵌套在 Map 接口内.

The static modifier is only allowed on a nested classes or interfaces. In your example Entry is nested inside the Map interface.

对于接口,static 修饰符实际上是可选的.这种区别对于接口没有意义,因为它们不包含任何可以访问外部 this 的代码.

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天全站免登陆