4 ms·
If you really did have a case where your list is a list of apples, wouldn't you type: List<Apple> apples = aps If you're using a general type Fruit, and can't
by ohnomrbill 11y ago
If you really did have a case where your list is a list of apples, wouldn't you type:
List<Apple> apples = aps
If you're using a general type Fruit, and can't stand any fruit that isn't an apple, you probably need to use the more specific Apple type.
- thomasahle 11y agoI mean, the problem of assigning `fruits = aps` is not that you get apples in your fruit list, but that now elements added to fruit (not of apple type) also get added to `aps`. The assignment sort of goes both ways like that.
- ohnomrbill 11y agoAh, your point makes more sense now. Immutability would help a lot here, it seems.