| 1 | = Refactoring of field initializers, instance initializers and static constructors = |
---|
| 2 | |
---|
| 3 | # In Java a class can have multiple instance initializers and class initializers. In D there are no instance initializer and only one static ctor is allowed. |
---|
| 4 | # In Java a field can be initialized in its declaration. The initialization can also include nearly every expression. In D an initializer must be a compile time module-local constant value. |
---|
| 5 | |
---|
| 6 | == Static ctors and initialization of static fields == |
---|
| 7 | If a static field initializer or a static initializer exists, TioPort generates a new static ctor, replacing the originals. |
---|
| 8 | This new static ctor contains all static field initializations and code of all static initializers. Every piece of code is placed in its own statement list. |
---|
| 9 | |
---|
| 10 | == Instance initializers and initialization of instance fields == |
---|
| 11 | If a non static field initializer of a instance initializer exist, TioPort generates a private method called "GENERATED_INSTANCE_INIT". All initializers and instance init code is moved into this method. Every piece of code is placed in its own statement list. |
---|
| 12 | |
---|
| 13 | After this step all ctors are searched. If the ctor does not have a call to another ctor of this class ( called "this" ), a call to the init method is inserted at the beginning of the ctor. |
---|
| 14 | |