| View previous topic :: View next topic |
| Author |
Message |
Aaron Zapashniy
Joined: 04 Jun 2006 Posts: 17 Location: Hungary
|
| Hi. i'm starting to add generics to a lot of my 1.4 code. i have a utility method which takes in a container of SuperClass. i'm now getting compile errors when i pass it a container of Subclass. why? |
| |
|
|
|
|
Starwarrior
Joined: 08 Jul 2006 Posts: 1
|
| Because a container of a superclass is not a superclass of a container of a subclass. |
| |
|
|
Aaron Zapashniy
Joined: 04 Jun 2006 Posts: 17 Location: Hungary
|
I.e. void doIt(List<Parent>){ ...} ... List<Child> list = new List<Child>(); doIt(list);
That's not legal? |
| |
|
|
Ikopar
Joined: 26 May 2006 Posts: 168
|
| No |
| |
|
|
Poolkop
Joined: 01 Jun 2006 Posts: 123
| |
Aaron Zapashniy
Joined: 04 Jun 2006 Posts: 17 Location: Hungary
|
| Hm. odd. how useful are these things then? |
| |
|
|
amoralis
Joined: 22 Jun 2006 Posts: 21
|
How about List<Parent> list = new List<Child>(); doIt(list); ?
Is that still invalid? |
| |
|
|
Ikopar
Joined: 26 May 2006 Posts: 168
|
| Yep |
| |
|
|
amoralis
Joined: 22 Jun 2006 Posts: 21
|
| <- doesn't get to use generics |
| |
|
|
Ikopar
Joined: 26 May 2006 Posts: 168
|
| It's unnecessary too |
| |
|
|
| Page 1 of 5 |
Goto page 1, 2, 3, 4, 5 Next |
|