| View previous topic :: View next topic |
| Author |
Message |
amoralis
Joined: 22 Jun 2006 Posts: 21
|
| It seems like it should be valid, please explain why it isn't valid |
| |
|
|
|
|
Ikopar
Joined: 26 May 2006 Posts: 168
|
List<Parent> list = new ArrayList<Parent>(); list.add(instanceOfChild);
Because generics don't work that way, there's no inheritence |
| |
|
|
amoralis
Joined: 22 Jun 2006 Posts: 21
|
| Ikopar: perhaps in that list instance you don't want parent to be accepted |
| |
|
|
Ikopar
Joined: 26 May 2006 Posts: 168
|
| Read the generics FAQ or tutorial, they cover this topic much better than I could |
| |
|
|
amoralis
Joined: 22 Jun 2006 Posts: 21
|
Perhaps you only want a specific child object there
Not that I have a use case but maybe Aaron Zapashniy does heh |
| |
|
|
Ikopar
Joined: 26 May 2006 Posts: 168
|
| You generally don't want that |
| |
|
|
Aaron Zapashniy
Joined: 04 Jun 2006 Posts: 17 Location: Hungary
|
I see. hm. interesting. okay.
Should still work fine, as 99% of the time i think i'm only performing parent methods when acting on collections. |
| |
|
|
amoralis
Joined: 22 Jun 2006 Posts: 21
|
| Generics in java kinda suck |
| |
|
|
Aaron Zapashniy
Joined: 04 Jun 2006 Posts: 17 Location: Hungary
|
Is it just me or does the term generics seem completely contrary to what they actually are?
They're not generics. they're specifics.
Treating things as Object is generic. |
| |
|
|
Gladis
Joined: 24 May 2006 Posts: 108
|
"templates" would be a better word for them.
Except that was taken. By something GOOD. |
| |
|
|
|