deep

a Cross Development Platform for Java

User Tools

Site Tools


dev:crosscompiler:class_initialization

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:crosscompiler:class_initialization [2015/04/06 13:29] – [Initialize Classes] ursgrafdev:crosscompiler:class_initialization [2021/05/10 19:52] (current) ursgraf
Line 14: Line 14:
 </code> </code>
 ==== When will a class be initialized? ==== ==== When will a class be initialized? ====
-On the host we have a situation like this. The class constructor of a top-level class will be called first. Then follows the method //main//. The class constructor of an imported class will be called when:+On the host we have a situation as follows. The class constructor of a top-level class will be called first. Then follows the method //main//. The class constructor of an imported class will be called when:
   * 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: the class constructor of a otherwise empty helper class calls all the other class constructors. This solution would also allow to get rid of the system table. 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: the class constructor of a otherwise empty helper class calls all the other class constructors. This solution would also allow to get rid of the system table.
    
-===== 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:
   }   }
 </code> </code>
-Die Objektkonstruktoren heissen alle //init// im Bytecode und unterscheiden sich in der Parameterliste. Block 1 und werden in //init// zusammengefasst+In the Bytecode these constructors carry the name //init// and vary in the parameter list. Block 1 and block in the above code block will be combined in //init//. 
-Beim Erzeugen eines Objektes wird stets zuerst mit Hilfe von //new// ein Block auf dem Heap alloziertAnschliessend wird der Konstruktor der Oberklasse aufgerufen (dieser ruft seinerseits den Konstruktor der Oberklasse auf). Diese Aufrufe sind im Bytecode enthalten+When creating an object a call to //new// allocates a block on the heapNext, the constructor of the super class is called (which itself calls its super class constructor). These calls can be found in the Bytecode. 
-Klassen dürfen auch Instanzinitialisierer enthaltenz.B. +Classes might also have instance initializerssuch 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;}
 </code> </code>
-Auch diese Instanzinitialisierer befinden sich im Bytecode in den Objektkonstruktoren.+These initializers go into the object constructors as well.
  
dev/crosscompiler/class_initialization.1428319757.txt.gz · Last modified: 2016/02/25 13:33 (external edit)