What are most important things you know about generics: hidden features, common mistakes, best and most useful practices, tips…
I am starting to implement most of my library/API using generics and would like to collect most common patterns, tips, etc., found in practice.
Let me formalize the question: What is the most important thing you’ve learned about generics?
Please try to provide examples — it would be easier to understand, as opposed to convoluted and overly-dry descriptions
Thanks
This question is somewhat similar to Jon’s question, though, on a different subject.
One of the most important things I’ve learned is that you can constrain the generic type parameter(s). This can be very powerful, allowing you to take customize the class for only certain types of objects and allowing you to use the members of that type in your generic class. I realize that this is pretty fundamental, but it’s one of the things that makes generics incredibly useful.