Re: Overriding Generics
- From: "Daniel Dyer" <"You don't need it">
- Date: Thu, 31 May 2007 20:11:07 +0100
On Thu, 31 May 2007 20:06:36 +0100, Bryan <BTRichardson@xxxxxxxxx> wrote:
Does anyone know why one can't override the following method
public List<Foo> getFooList()
with something like this
public List<Bar> getFooList()
if Bar extends Foo?
Because List<Bar> is not a sub-type of List<Foo>, even if Bar is a sub-type of Foo.
ArrayList<Foo> is a sub-type of List<Foo>, as is LinkedList<Foo>.
To extend the method as you wish, the super-type method would have to be:
List<? extends Foo> getFooList()
Then List<Bar> getFooList() would be fine.
Dan.
--
Daniel Dyer
http//www.uncommons.org
.
- Follow-Ups:
- Re: Overriding Generics
- From: Tom Hawtin
- Re: Overriding Generics
- References:
- Overriding Generics
- From: Bryan
- Overriding Generics
- Prev by Date: Overriding Generics
- Next by Date: Re: DateFormat question
- Previous by thread: Overriding Generics
- Next by thread: Re: Overriding Generics
- Index(es):