Show Me Your Generic Part 2
Only few hours passed after I had posted a post about misusing generics when I spotted a real gem during the code review. Here it is:
Cool, right? Here we have all sort of coolness: class level generics, method level generics and even generic constraints. However, this code can be simplified. Just check this out:
Yes, exactly. We don’t need method level generics here, because, you know, they only intention was to restrict an argument to be a subtype of some interface. And this can be achieved by just using proper signature. Note that as Sergey Teplyakov mentioned in comment below, the latter makes sense if implementations of IFoo
and IBoo
structs. But in our particular case those were not (and I don’t remember seeing structs being used in such a way).
Well, code does not longer look very smart, but good code should be simple, and not always smart.
Enjoy your coding :)