6

What's the advantage of making a class generic as oppose to just make the method generic? Under which circumstance would you want to use a generic class?

Skepti_Capy
  • 107
  • 7
  • 1
    https://stackoverflow.com/questions/77632/what-is-cool-about-generics-why-use-them –  Oct 05 '17 at 02:01

1 Answers1

4

Here are some of my list:

  • With generic class, you can have generic properties as well. Which you can use together with generic methods you have on your generic class.

  • For code reusability. You don't want to call again the same generic method on different non-generic class, although you can do that, but not a good practice though. You want to put all your related generic methods under generic class.

  • With generic class, what you pass on the type of entity in class, can be used by all generic methods and generic properties. With only generic method, you cannot re-use that, unlike with a generic class.
Willy David Jr
  • 8,604
  • 6
  • 46
  • 57