Chapter 3: Parameterized typing with generics: 3.3.2
Last updated: 5/7/2008
Joe Albahari pointed out that a good example of a method where you always have to specify the type parameter is
Activator.CreateInstance<T>(). With no "normal" parameters, there's nothing for the type inference rules to work with. This is interesting on two counts:
- This method is used by the C# compiler when you call
new T() where
T is a type parameter with a constructor type constraint.
- The generic type inference in Java could cope with this situation, if you were assigning to an appropriate type of variable. It has special rules for type inference in the case of assignments.