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

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

问题描述

我今天使用了 Eclipse 的拉取接口"重构特性,基于现有类创建了一个接口.该对话框提供将新接口的所有新方法创建为抽象"方法.

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.

这样做有什么好处?

我认为允许您将接口方法声明为抽象的这一事实是该语言的一种多余且无害的特性,但并不特别鼓励.

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.

为什么 Eclipse 会支持这种风格,或者为什么会有人自愿选择这样做?

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.

推荐答案

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

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

也就是说,由于 Java 具有向后兼容性的倾向,我真的怀疑 abstract 关键字是否存在会有所不同.

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