Why can't Delphi infer the type for the TEnumerable <T> parameter?
Consider the following utility class declaration in Delphi 2010:
TEnumerableUtils = class
public
class function InferenceTest<T>(Param: T): T;
class function Count<T>(Enumerable: TEnumerable<T>): Integer; overload;
class function Count<T>(Enumerable: TEnumerable<T>; Filter: TPredicate<T>): Integer; overload;
end;
Somehow the output about the compiler seems to have problems:
var
I: Integer;
L: TList<Integer>;
begin
TEnumerableUtils.InferenceTest(I); // no problem here
TEnumerableUtils.Count(L); // does not compile: E2250 There is no overloaded version of 'Count' that can be called with these arguments
TEnumerableUtils.Count<Integer>(L); // compiles fine
end;
The first call works as expected, and T is correctly output as Integer.
The second call does not work, if I have not added <Integer> yet , then it works, as can be seen from the third call. Am I doing something wrong or is it type inference in Delphi that just doesn't support it (I don't think this is a problem in Java, so I expected it to work in Delphi as well).
+5
1 answer