Great, in general it does not have this benefit even. It may exist, but it is rare to find a case like this.
Has 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 team and he considered that a team is a list of players.
But actually a team is a team. A team possesses a list of players. According to the liskov principle, inheritance should only occur when actually one type is the same as the other type. A team cannot 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 they say to prefer composition in place of inheritance. Heritage is overrated.
I do not know the context of this case, the question does not speak well what this is ListAdapter
, if only to create a specialized list of Item
, must be a mistake.
If it is to use with some legacy code that requires a specialized list and not a generic list, then all right, started wrong, do what? You’re using a bad API, do what you have to do, "Get your hands dirty".
In the other answer it talks about using when you really need to extend a list and add a behavior. Ok, that’s a reason that would be valid. But it’s not usually real. If you need to manipulate something inside the list that has something protected, it would be useful. But there’s nothing protected in ArrayList
. What is private cannot be manipulated anyway. What is public can be done with a utility method outside the class. In general inheritance is not only necessary because of this, because it is not expected to use this new method that would be added in any existing API. And in new code you are creating you can use the utility method. Don’t say never, but in general inheritance also makes no sense at this point.
I even did a little research to see where to use one ListAdapter
and found that Android uses. But note that they did right, this kind inherits from Adapter
, that is, an adaptor list is an adaptor, not a list. It has nothing to do with what was asked in the question.
Your intuition seems to be right. Unless you have a larger context that indicates your use.
Massa, I learned real young.
– Aline