My coworker made the claim that there is never a need to use Object when declaring variables, return parameters, etc in .NET 2.0 and newer.
He went further and said in all such cases, a Generic should be used as the alternative.
Is there any validity to this claim? Off the top of my head I use Object for locking concurrent threads…
Generics do trump
objectin a lot of cases, but only where the type is known.There are still times when you don’t know the type –
object, or some other relevant base type is the answer in those instances.For example:
You won’t be able to cast that result or maybe even know what the type is at compile time, so
objectis a valid use.Your co-worker is generalising too much – perhaps point him at this question. Generics are great, give him that much, but they do not “replace”
object.