【问题标题】:Parent and child classes implementing a common interface, repeatedly重复实现公共接口的父类和子类
【发布时间】:2011-07-06 01:10:47
【问题描述】:

今天我在我的代码中发现一个子类实现了父类已经继承的接口。

我可以知道这是否有任何不利的副作用或意图,因为我正在努力将其从子类中删除,因为我认为这可能是一个意外错误,或者我可能遗漏了什么?

在子类中:

public class ProductServiceBean
  extends GenericSessionBean
  implements javax.ejb.SessionBean

在父类中:

// Compiled from GenericSessionBean.java (version 1.2 : 46.0, super bit)
public abstract class weblogic.ejb.GenericSessionBean 
  extends weblogic.ejb.GenericEnterpriseBean 
  implements javax.ejb.SessionBean

请注意,在子级和父级中,这些类都实现了javax.ejb.SessionBean

【问题讨论】:

标签: java inheritance ejb-2.x implements


【解决方案1】:

ProductServiceBean 类中删除implements javax.ejb.SessionBean 将无效,因为该类实现接口的事实是从父GenericSessionBean 类继承的。

将它包含在子类中也没有什么坏处,它只是一个多余的声明。

【讨论】:

    【解决方案2】:

    让子级和父级都实现相同的接口没有额外的影响。相当于让父级只实现该接口。

    【讨论】:

      猜你喜欢
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多