The alternative, using object instead of T, would cause the function to return object.
When it returns T, you can do something like:
addAndReturn(myElement, col).SomeMethodOfMyElement();
If addAndReturn returned object instead, you would have to use either
((MyElementType)addAndReturn(myElement, col)).SomeMethodOfMyElement();
which needs an explicit cast, or
addAndReturn(myElement, col);
myElement.SomeMethodOfMyElement;
which needs two statements instead of one.
EDIT: Now that your question has been formatted, I see that one of the parameters is Collection<T>
. In that case, the generic syntax ensures that
addAndReturn(mySquare, collectionOfCircles);
returns a compile-time error instead of a run-time error.
EDIT: And just in case your question was about the <T>
syntax rather than about the use of generics in general: The <T>
tells the compiler that the T
used in the method definition is not some class T but rather a placeholder for whatever class "fits" for a specific call of the method.