java嵌套接口和内部类 [英] java nested interfaces and inner classes

查看:165
本文介绍了java嵌套接口和内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么java嵌套接口不能是非静态的?为什么一个内部类不能包含静态非最终成员?

Why can't a java nested Interface be non-static ? And why can't an inner class contain static non final members ?

我在浏览Gosling时遇到了这些问题并且还没有找到答案。

I came across the questions while going through Gosling and haven't been able to figure out the answer yet.

推荐答案

如果嵌套类是非静态的(即内部类),这意味着它的每个实例都被绑定到外部类的一个实例。由于接口没有自己的实例,因此将实现类绑定到外部对象似乎没有用,因此默认情况下将其设置为静态似乎是合理的。

If an nested class is non-static (i.e. an inner class), this means that each instance of it is bound to an instance of the outer class. As an interface has no instances of its own, it seems to not be useful for the implementing classes to be bound to an outer object, so having it static by default seems reasonable.

这篇关于java嵌套接口和内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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