Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #772
| Date | 2011-06-14 21:31 +0100 |
|---|---|
| From | Neil Morris <neil.morris4@googlemail.com> |
| Newsgroups | comp.lang.java.help |
| Subject | Re: generics |
| References | <AqGdnSMWq6oC5mvQnZ2dnUVZ7rOdnZ2d@brightview.co.uk> |
| Message-ID | <6sGdncrNDqC4WGrQnZ2dnUVZ8k6dnZ2d@brightview.co.uk> (permalink) |
On 13/06/2011 22:05, Neil Morris wrote:
> 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
To better explain want I was trying to ask, if the above examples i had
the plain vanilla types ie
instead of i had
Cage<Animal> Cage(Animal animal)
Cage<Lion> Cage(Lion lion)
etc.. and barring any syntax errors as noted by one poster
having the two following syntax errors included!!!!!
animalCageLionGenerics = new Cage<Lion>
animalCageLionOldShool = new Cage(Lion lion)
animalCageCatGenerics = new Cage<Cat>
animalCageCatOldSchool = new Cage(Cat cat)
given that generics and old school/old style above, could old school
have statements as follows
animalCageLionOldSchool=animalCatOldSchool \\ ??????legal?????
thanks in advance
Back to comp.lang.java.help | Previous | Next — Previous in thread | 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