0

May be I am missing some understanding or may be I am unable to understand some "wording" (I am fairly new to JAVA and android), but if you look at the developer reference docs for android, then one can find that an interface is "implementing" another interface. For example, among others, look at ComponentCallbacks2 & SurfaceHolder.Callback2. But, as per an SO post, an interface cannot implement another interface, it can only extend one. So, what is going on in the android reference docs? Shouldn't the keyword "extends" be used in the android reference docs, instead of "implements" when it comes to relationships between interfaces?

Also, say an interface interfaceB implements another interface interfaceA and a class, say ClassXYZ, implements interfaceB. While declaring the class in the reference docs, sometimes it is mentioned as:

public class ClassXYZ implements interfaceB 

(for example, in the declaration of Activity, it is mentioned that Activity class implements ComponentCallbacks2, but it is not mentioned that Activity implements ComponentCallbacks even if ComponentCallbacks2 "implements" ComponentCallbacks2)

and sometimes as

public class ClassXYZ implements interfaceB, interfaceA

(for example, in the declaration of AlteredCharSequence, it is mentioned that AlteredCharSequence class implements CharacterSequence, and it is mentioned that AlteredCharSequence implements GetChars even if GetChars "implements" CharSequence)

What is the difference between the two declarations? How does the class inheritance diagram look in both the cases?

2
  • I think the android docs are simply using the wrong terminology. ComponentCallbacks2 extends ComponentCallbacks. Interfaces are not implementations. See some source. Commented Apr 17, 2019 at 17:29
  • @khelwood Thanks, can you answer the second part of the question? (The one that starts with "Also say") Commented Apr 17, 2019 at 17:32

1 Answer 1

1

I think the android docs are simply using the wrong terminology. ComponentCallbacks2 extends ComponentCallbacks. Interfaces are not implementations. See some source.

As for the rest, if interface B extends interface A, then any implementation of B is also an implementation of A, even if the documentation fails to describe it as such. So any class that implements ComponentCallbacks2 does implement ComponentCallbacks, whether the docs mention it or not.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, but should the parent interface be mentioned in the class declaration of the class that implements B?
There is no need to mention it in the class declaration. It also does no harm to mention it, if it helps readers understand the purpose of the class.
So, say a Class C implements B (which extends A). Then are both the following are correct?: 1) class C implements B 2) class C implements B, A

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.