class-constructors

Delphi XE: class constructor doesn't get called in a class using generics

情到浓时终转凉″ 提交于 2019-11-30 07:27:22
问题 Consider the following example (I am using 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 :=

Delphi XE: class constructor doesn't get called in a class using generics

本小妞迷上赌 提交于 2019-11-29 03:56:05
Consider the following example (I am using 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. The class constructur is never called and hence the

Returning in a static initializer

回眸只為那壹抹淺笑 提交于 2019-11-28 01:50:36
This isn't valid code: public class MyClass { private static boolean yesNo = false; static { if (yesNo) { System.out.println("Yes"); return; // The return statement is the problem } System.exit(0); } } This is a stupid example, but in a static class constructor we can't return; . Why? Are there good reasons for this? Does someone know something more about this? So the reason why I should do return is to end constructing there. Thanks I think the reason is that initializers are carried together with field initializations (and with constructors, in the case of instance initializers). In other

Returning in a static initializer

[亡魂溺海] 提交于 2019-11-26 22:01:34
问题 This isn't valid code: public class MyClass { private static boolean yesNo = false; static { if (yesNo) { System.out.println("Yes"); return; // The return statement is the problem } System.exit(0); } } This is a stupid example, but in a static class constructor we can't return; . Why? Are there good reasons for this? Does someone know something more about this? So the reason why I should do return is to end constructing there. Thanks 回答1: I think the reason is that initializers are carried