Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #767
| Date | 2011-06-13 22:05 +0100 |
|---|---|
| From | Neil Morris <neil.morris4@googlemail.com> |
| Newsgroups | comp.lang.java.help |
| Subject | generics |
| Message-ID | <AqGdnSMWq6oC5mvQnZ2dnUVZ7rOdnZ2d@brightview.co.uk> (permalink) |
I have been reading through the java tutorial on generics, and have a
question relating to them.
Firstly as from the java tutorial, if I had the following 'Cage' class
interface Animal { ... }
interface Lion extends Animal { ... }
interface cat extends Animal { ... }
public Cage<E> extends Collection<E> { ... }
Cage<Animal> animalCage=new Cage<animal>
Cage<Lion> lionCage=new Cage<lion>
Cage<cat> catCage=new Cage<cat>
with the above definitions Cage is a subclass of Collection, but with
generics as i understand it the various cages ie Cage<animal> Cage<lion>
and Cage<cat> are not interchangable as below
lionCage.add(catCage)// not allowed!!! even though lionCage and
castCage are subclasses of Collection
could this be because that the various Cages take differant parameters?
thanks in advance
Neil Morris
Back to comp.lang.java.help | Previous | Next — Next in thread | Find similar
generics Neil Morris <neil.morris4@googlemail.com> - 2011-06-13 22:05 +0100
Re: generics markspace <-@.> - 2011-06-13 17:49 -0700
Re: generics Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-14 01:48 -0400
Re: generics Ian Shef <invalid@avoiding.spam> - 2011-06-14 19:45 +0000
Re: generics Neil Morris <neil.morris4@googlemail.com> - 2011-06-14 21:31 +0100
Re: generics markspace <-@.> - 2011-06-14 14:21 -0700
Re: generics Lewis Bloch <lewisbloch@google.com> - 2011-06-16 07:05 -0700
Re: generics Patricia Shanahan <pats@acm.org> - 2011-06-16 11:40 -0700
Re: generics Gene Wirchenko <genew@ocis.net> - 2011-06-16 15:14 -0700
csiph-web