Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is class of T not allowed in a generic type?

Tags:

delphi

Consider this program:

type
  TMyClass<T: class> = class
  public type
    TClassOfT = class of T;
  end;

begin
end.

This fails to compile at the declaration of TClassOfT with the error message:

E2021 Class type required

Can anyone explain why this is so? If I were to instantiate this class with, for instance TMyClass<TObject> then surely class of TObject would be meaningful. I constrained the generic parameter to be a class. So how can the compiler object that T is not a class type?

like image 590
David Heffernan Avatar asked Dec 14 '13 15:12

David Heffernan


1 Answers

So far as I can tell, there is no reason for the compiler to reject this code. Thus, I believe that it is a design flaw and have submitted QC#121178.

like image 69
David Heffernan Avatar answered Nov 16 '22 01:11

David Heffernan