java - 在 Java 中,什么时候应该在接口(interface)中使用抽象方法?

标签 java interface coding-style abstract-methods

我在 Java 中有以下接口(interface)

public interface IFoo
{
    public abstract void foo();
    public void bar();
}

foo() 和 bar() 有什么区别? 什么时候应该使用摘要?

两者似乎都能实现我想要的,除非我遗漏了一些微妙的东西?

更新 Why would one declare a Java interface method as abstract? 的副本

最佳答案

没有任何功能差异。 Java 接口(interface)中从未提供任何实现,因此所有方法声明都是隐式抽象的。

参见[1]:http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html

上面的直接引用:

Note: All of the methods in an interface (see the Interfaces section) are implicitly abstract, so the abstract modifier is not used with interface methods (it could be—it's just not necessary).

关于java - 在 Java 中,什么时候应该在接口(interface)中使用抽象方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1492359/

相关文章:

java - 使用 JSF 2.2 的 Google App Engine 中的文件上传错误

子类中的 C++ 收紧函数参数类型

java - Android Edittext 共享首选项

java - 如何验证 ipv4 ipv6 和 dns 名称?

java - 比较原始类型

C# - 在另一个方法中实现抽象或接口(interface)方法

java默认方法不起作用

bash - 解析 BASH 脚本中的 heredoc 注释

Java在try-catch-finally机制中的返回值

parameters - 多少个构造函数参数就太多了?