Search code examples
javalistinterfaceparameterized

Can a parameterized interface be a subinterface?


This is a homework assignment that I've been researching for over 2 hours and I still can't get a decent answer, so I would appreciate any help.

Suppose that Bicycle is a subclass of Vehicle.

Is the parameterized interface List<Bicycle> a subinterface of List<Vehicle> ? Explain briefly.

My issues are:

  1. I thought you couldn't even have lists in interfaces, only methods.

  2. How can a list be an interface, let alone a subinterface?

  3. What is this question even asking, in plain English? :/

Thanks in advance!


Solution

  • Regarding your issues

    1. You are not HAVING a List in an interface, List itself is an interface.

    2. List of course IS an interface (LinkedList and ArrayList being the classes implementing it). List just provides methods enough to describe a simple list, and ArrayList and LinkedList provide bodies of those method according to the implementation.

    3. To explain the actual question, I'll jot down some facts first. (Sorry if I'm going too basic, but I'm doing it for the sake of completion.)


    Regarding the question

    • Subinterface means the interface that extends another interface.
    • Parametrized interface is the interface which take a class type as a parameter while creating a reference. e.g. List<Vehicle> means List is a parametrized interface which has been given Vehicle as it's parameter. (Here it means each element of List is a Vehicle. i.e. it's a list OF vehicles).
    • The question is asking whether a parameterized interface List<Bicycle> is a subinterface of List<Vehicle>. (i.e. if List<Bicycle> extends List<Vehicles> given the fact that Bicycle extends Vehicle.

    I suppose it should be enough for you to understand the question and partly the answer too..

    Good luck.