javaoopsupertype

Are supertypes of a type just the ones that are directly extended or implemented?


For example ArrayList extends AbstractList and implements List, RandomAccess, Cloneable, Serializable. Are these the only supertypes or do we also mean AbstractCollection and Object are supertypes of Arraylis?

I am currently having a class for JAVA and working on a project. Among other things I need to find the types of the program that has the most supertypes using Reflecion API. I need to know if I must include "indirect" supertypes.


Solution

  • I think it's a matter of whose terminology you are referring to as there's no universally accepted definition; however, I would say that indirect supertypes are certainly supertypes. For example, you might write a class MyList implements List. Then later you decide to extend AbstractList. You keep the same behaviour of MyList but the fact it now extends AbstractList is an implementation detail. MyList is still a subtype of List. (In this definition, I'm using "type" to refer to both interfaces and classes.)