Great, it usually does not have that benefit. It may exist, but it is rare to find such a case.
You have a famous question in Eric Lippert's OS that talks about it . It shows that the AP wanted to create a list that is a time and he considered that a team is a list of players.
But in fact a team is a team. A team has a list of players. According to the Liskov principle , inheritance should only occur when one type is actually the same as the other type. A team can not inherit from a list, a team is not a list, but it is composed of a list of players, possibly other properties as well.
That's why you're often told to prefer composition instead of inheritance . Inheritance is overvalued.
I do not know the context of this case, the question does not speak well what this ListAdapter
is, if it is only to create a specialized list of Item
, it should be an error.
If it is to use with some legacy code that requires a specialized list and not a generic list, then okay, do what? You are using a bad API, do what you have to do, "hold hands."
In the other answer you talk about using when you really need to extend a list and add a behavior. Okay, that's a valid reason. But it is not usually true. If you need to manipulate something internal in the list and have something protected, it would be useful. But there is nothing protected in ArrayList
. What is private can not be manipulated anyway. What is public can be done with a utility method external to the class. Inheritance is usually not necessary just because of this, because you are not expected to use this new method that would be added to any existing APIs. And in new code you are creating you can use the utility method. Do not say never, but in general inheritance does not make sense at this point either.
I even ran a search to see where to use ListAdapter
and found that Android uses . But note that they were made right, this type inherits from Adapter
, that is, an adapter list is an adapter, not a list. It has nothing to do with what was put in the question.
Your intuition seems to be right. Unless it has a larger context that indicates its use.