Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 754741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:02:56+00:00 2026-05-14T15:02:56+00:00

Consider the following declaration of a generic utility class in Delphi 2010: TEnumerableUtils =

  • 0

Consider the following declaration of a generic utility class 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 compiler type inference seems to have problems here:

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 inferred as Integer.

The second call does not work, unless I also add <Integer> — then it works, as can be seen in the third call. Am I doing something wrong or is the type inference in Delphi just not supporting this (I don’t think it is a problem in Java which is why expected it to work in Delphi, too).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:02:56+00:00Added an answer on May 14, 2026 at 3:02 pm

    The compiler would need to do pattern matching to infer parameter types; it currently does not. The compiler is limited to quite simple inference – if the parameter type is of a type parameter type, then the compiler can figure it out, but not much beyond that.

    The argument type in your example is not a simple type parameter, but is rather a constructed generic type (it’s constructed with the method’s type parameter T, but it is constructed none the less). The compiler needs to make two inferences in order to find out the value of T. First, it needs to see that the constructed type’s generic type is an ancestor of TList<T>‘s generic type; and it also needs to match the type parameter T in the constructed type’s type parameter list with the concrete type Integer in TList<T>‘s ancestor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following Java function: public void foo(Class<? extends Exception> cl, List<? extends Exception>
Consider the following class declaration: #include classB.h class A { private: B *prop; public:
Consider the following Java class declaration: public class Test { private final int defaultValue
Consider following 2 programs giving same error First calss: public class Testing { Testing
Consider the following function declaration for checking current language on a bilingual website: function
Consider the following class in a file MyClass.cs using System; public class MyClass :
consider the following class declarations: namespace X { template<class T> class Foo { public:
I have the following snippet of code. abstract class MrParent { public function __construct()
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
I have faced the following interview question. Consider this function declaration: void quiz(int i)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.