为什么会将Java接口方法声明为抽象? [英] Why would one declare a Java interface method as abstract?

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

问题描述

我今天使用Eclipse的pull interface重构功能来创建一个基于现有类的接口。该对话框提供用于创建新界面的所有新方法为抽象方法。



这样做的好处是什么?



我认为你被允许将接口方法声明为抽象的事实是这种语言的多余和无害的特征,并没有被特别鼓励。



为什么Eclipse支持这样的风格,或者为什么自愿选择这样做?



澄清:我不是问为什么接口方法是抽象的,就是明显。我问为什么要明确地选择将它们标记为抽象的,因为如果他们在一个接口中是抽象的。

解决方案

根据 Java语言规范,接口的 abstract 关键字已经过时,不应再使用。 (第9.1.1.1节)



那就是说,对于Java的向后兼容性的倾向,我真的怀疑,无论 / code>关键字存在。


I used the "pull interface" refactoring feature of Eclipse today to create an interface based on an existing class. The dialog box offered to create all the new methods of the new interface as "abstract" methods.

What would be the benefit of that?

I thought that the fact that you were allowed to declare interface methods as abstract was a superfluous and harmless feature of the language that is not particularly encouraged.

Why would Eclipse support such a style, or why would someone voluntarily choose to do so?

Clarification: I am not asking why interface methods are abstract, that is obvious. I am asking why one would explicitly choose to mark them as abstract since if they're in an interface they are abstract anyway.

解决方案

According to the Java Language Specification, the abstract keyword for interfaces is obsolete and should no longer be used. (Section 9.1.1.1)

That said, with Java's propensity for backwards compatibility, I really doubt it will ever make a difference whether the abstract keyword is present.

这篇关于为什么会将Java接口方法声明为抽象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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