As Mark said, it is sometimes useful to overload a type to have a non-generic class - and that would be the case.
Why is this necessary, suppose that the static method was actually implemented as:
public static BinarySearchTree<char> InitializeSampleCharacterBST() { Console.WriteLine(typeof(T)); return null; }
This would be a perfectly valid code - it would be in a generic type, so it should have access to the type parameter ... but you are trying to call the method without providing a type type parameter, so it couldnβt Work. In your case, you are not using T anywhere in the method, but it is a coincidence. This is a bit like an instance method that does not use this : you are not using an instance, but you still cannot call it as if it were a static method.
Besides having separate static classes, another design method that might be useful is to split your type into non-general and common elements. Thus, in cases where it may be inconvenient to work out the exact type that you have, you really don't need to know it to call some of the members. For example, a collection interface hierarchy may have:
public interface ISomeCollection { int Count { get; } void Clear(); } public interface ISomeCollection<T> : ISomeCollection { void Add(T item); }
I myself used this technique for my port of protocol buffers in C #, and it turned out to be very useful (if somewhat complicated).
source share