×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

Sorry, could you explain your problem in detail?

Let me do some quess work.

1) If both interface A and B have the same contents and their only difference is in their names, it means you don't need two two interfaces. If you really need two Java data types, you may have interface A hold all the methods, and interface not to contain any methods. (This is the co-called Marker Pattern).

2) If Interfaces A and B share some methods but B has more methods, you may have B extend A.

public interface A{
//some methods
}

public interface B extend A{
//some NEW methods
}


public class MyClass implements B {
//implement all the methods in A nd B
//Introduce new methods
}

In any case, I think it is agaist to the business rule to have two interfaces who have the same contents.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / If I have to implement two interface which have same function in one class, how can i do it?
    • Sorry, could you explain your problem in detail?
      Let me do some quess work.

      1) If both interface A and B have the same contents and their only difference is in their names, it means you don't need two two interfaces. If you really need two Java data types, you may have interface A hold all the methods, and interface not to contain any methods. (This is the co-called Marker Pattern).

      2) If Interfaces A and B share some methods but B has more methods, you may have B extend A.

      public interface A{
      //some methods
      }

      public interface B extend A{
      //some NEW methods
      }


      public class MyClass implements B {
      //implement all the methods in A nd B
      //Introduce new methods
      }

      In any case, I think it is agaist to the business rule to have two interfaces who have the same contents.