次の例を考えてみましょう (私は Delphi XE を使用しています)。
program Test;
{$APPTYPE CONSOLE}
type
TTestClass<T> = class
private
class constructor CreateClass();
public
constructor Create();
end;
class constructor TTestClass<T>.CreateClass();
begin
// class constructor is not called. this line never gets executed!
Writeln('class created');
end;
constructor TTestClass<T>.Create();
begin
// this line, of course, is printed
Writeln('instance created');
end;
var
test: TTestClass<Integer>;
begin
test := TTestClass<Integer>.Create();
test.Free();
end.
クラスコンストラクターは呼び出されないため、「作成されたクラス」という行は出力されません。ただし、一般化を削除TTestClass<T>
して標準クラスTTestClass
にすると、すべてが期待どおりに機能します。
ジェネリックで何かを見逃していますか?それとも単に機能しませんか?
これについての考えは高く評価されます!
ありがとう、 -- ステファン --