|
|
|
|
|
by thomascgalvin
1990 days ago
|
|
Generics aren't magic, and they aren't Turing complete, like C++ templates. They're just a way to avoid copy-pasting code. Having `Set<Foo>` and `Set<Bar>` is far more readable than `class FooSet` and `class BarSet`, where the code is exactly the same aside from a search-and-replace. You also run into issues where someone finds a bug in `FooSet`, but doesn't know `BarSet` exists, and forgets to patch both. Now, you have two divergent copy-paste classes. Generics solve a bunch of real-world problems, in a very simple manner. |
|
The only real cases I can see is creating new data structures, (for instance if you wanted to create your own map type).