为什么嵌套接口隐式声明为静态? [英] Why are nested interfaces declared implicitly static?

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

问题描述

正如标题所说,为什么嵌套接口是隐式静态的。为什么我不能像嵌套类一样使用嵌套接口,例如静态和无静态

解决方案

oracle文档


内部类与其封闭类
的实例相关联,并且可以直接访问该对象的方法和字段


ie它保持对其封闭实例的引用。



另一个接口,它只是类型的静态定义。一个契约,用于提供一些多态性。



接口本身不能被实例化,因此它不能具有状态,因此它无法知道封闭的实例。 / p>

as the title says, why nested interfaces are implicitly static.Why cant i use nested interfaces just like nested classes ie like with static and without static

解决方案

From the oracle documentation:

an inner class is associated with an instance of its enclosing class and has direct access to that object's methods and fields

i.e. it maintains a reference to its enclosing instance.

An interface on the other and is just a static definition of type. A contract, used to provide some polymorphism.

An interface cannot itself be instantiated, therefor it cannot have state, and thus it cannot "know" about an enclosing instance.

这篇关于为什么嵌套接口隐式声明为静态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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