Java接口继承和实现

3

我在Apache Camel源代码中看到了这样的一段:

public class DefaultCamelContext extends ServiceSupport implements CamelContext, Service

我的问题是为什么这个定义是这样的:

public interface CamelContext extends Service

以及

public abstract class ServiceSupport implements Service

难道不应该只是这样吗?
public class DefaultCamelContext extends ServiceSupport implements CamelContext

是否需要明确使用“implements Service”,我是否遗漏了什么?通常有哪些情况下可能需要使用它呢?


https://dev59.com/5HRC5IYBdhLWcg3wP-j4 - erickson
1个回答

6

这不是必须的,但它强调了任何阅读代码的人它确实实现了Service - 这意味着他们不需要查看ServiceSupport来找到这个信息。

我自己不倾向于这样做,但这样做并没有什么问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接