Why use interfaces "A" and "B" when "B" extends "A",

Suppose I have the following code ...

interface A{
  void a();
}

interface B extends A{
  void b();
}

class ImplementOne implements B{ 
  public void a(){};
  public void b(){};
}     

class ImplementTwo implements B, A{ 
  public void a(){};
  public void b(){};
} 

Regardless of whether the ImplementTwo class implements either B or A or just B, it still needs to implement the a () method on interface A, because interface B extends interface A. Is there any reason that will explicitly execute

...implements B, A

instead

...implements B  

?

+4
source share
7 answers

IMO - , , - , . , , , , , , , , - .

+2

. -, , . :

Class<?>[] interfaces = ImplementTwo.class.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
    System.out.println(interfaces[i]);
}

, implements B, A, implements B .

, true :

A.class.isAssignableFrom(ImplementTwo.class)
+5

- Serializable.

: Serializable, - Serializable, Serializable.

. , .

+2

. (, , A, B).

+1

, ( ).

, . / .

+1

. implements A, B implements B, A-B

0

. , . .

0

All Articles