Java中的最终接口? [英] Final interface in Java?

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

问题描述

接口是否可以在Java中声明为final?

Can an interface be declared as final in Java?

推荐答案

接口是100%抽象的,是创建一个接口的唯一方法接口的实例是实例化实现它的类。允许接口 final 完全没有意义。

Interfaces are 100% abstract and the only way to create an instance of an interface is to instantiate a class that implements it. Allowing interfaces to be final is completely pointless.

编辑问题不是我最初想的就是彻头彻尾的离谱。最终接口是一个不能被其他接口扩展但可以在表面上实现的接口。

EDIT The questions is not as outright outrageous as I first thought. A final interface is one that cannot be extended by other interfaces but can be implemented ostensibly makes sense.

我可以想到最终类和最终界面之间的一个区别。扩展类可能会损害其完整性,因为它包含某些状态。扩展接口只会增加操作,并且不会损害实现的完整性,因为接口本身是无状态的。

I could think of one difference between a final class and a final interface. Extending a class can compromise its integrity because it contains some state. Extending an interface simply adds operations and cannot compromise the integrity of the implementation because the interface is stateless on its own.

这篇关于Java中的最终接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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