5 ms·
What's so good about that? Isn't it more convenient to be able to store different types together in the same collection?
by tocomment 13y ago
What's so good about that? Isn't it more convenient to be able to store different types together in the same collection?
- sluukkonen 13y agoIt can be more convenient, but the added type safety prevents the programmer from doing many kinds of common mistakes. It's a trade-off.
- coldtea 13y agoNo. You typically want different types of the same kind, or of the same family (e.g numeric types or types that extend some interface, etc), not every random thing thrown in. If it was truly whatever type, how would you know what to do with it when you got it out of the collection? E.g foo = myColection.get(2); foo.?????? (what operations can foo afford?)