考虑这个程序:
type
TMyClass<T: class> = class
public type
TClassOfT = class of T;
end;
begin
end.
Run Code Online (Sandbox Code Playgroud)
这无法在声明中编译TClassOfT并显示错误消息:
E2021 Class type required
任何人都可以解释为什么会这样吗?如果我要实例化这个类,TMyClass<TObject>那么肯定class of TObject会有意义.我将泛型参数约束为一个类.那么编译器对象怎么能T不是类类型呢?