This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dev:crosscompiler:class_initialization [2015/04/06 13:29] – [Initialize Classes] ursgraf | dev:crosscompiler:class_initialization [2021/05/10 19:52] (current) – ursgraf | ||
---|---|---|---|
Line 14: | Line 14: | ||
</ | </ | ||
==== When will a class be initialized? | ==== When will a class be initialized? | ||
- | On the host we have a situation | + | On the host we have a situation |
* accessing a static field of an imported class | * accessing a static field of an imported class | ||
* calling a static method of an imported class | * calling a static method of an imported class | ||
Line 40: | Line 40: | ||
Java does not define the order of initialization clearly. If tests on the host and the target should lead to the same result, the following solution would be appropriate: | Java does not define the order of initialization clearly. If tests on the host and the target should lead to the same result, the following solution would be appropriate: | ||
- | ===== Initialisierung von Objekten | + | ===== Initialization of Objects |
- | Die Initialisierung von Objekten wird in den Objektkonstruktoren zusammengefasst. | + | The initialization of objects is done in the object constructors. |
<code java> | <code java> | ||
int len = 4; // block 1 | int len = 4; // block 1 | ||
Line 50: | Line 50: | ||
} | } | ||
</ | </ | ||
- | Die Objektkonstruktoren heissen alle // | + | In the Bytecode these constructors carry the name // |
- | Beim Erzeugen eines Objektes wird stets zuerst mit Hilfe von // | + | When creating an object a call to // |
- | Klassen dürfen auch Instanzinitialisierer enthalten, z.B. | + | Classes might also have instance initializers, such as: |
<code java> | <code java> | ||
int[] data = new int[10]; | int[] data = new int[10]; | ||
{for (int i = 0; i < 10; i++) data[i] = i;} | {for (int i = 0; i < 10; i++) data[i] = i;} | ||
</ | </ | ||
- | Auch diese Instanzinitialisierer befinden sich im Bytecode in den Objektkonstruktoren. | + | These initializers go into the object constructors as well. |