Home
 Introduction
 Using Holon
 Holon Tools
 Contact


 HolonJ

 HolonJForth
    Classes
    Methods
    Parameter
    Variables
    Forth
    FlowControl
    Compiler
    Libraries
    Constructors
    Exceptions 

 UsingHolonJ

Constructors

Initial Values

The conventional Java compiler silently adds two methods to a class file, which serve to set the variables to initial values. When you write  int X = 7, Java compiles the "= 7" operation in the method <init>, if X is an instance variable, or in the method <clinit>, if X is a static class variable. In HolonJ the mechanism is open. We write the initialization methods explicitly, if there are values to initialize. 

You don't have to initialize zero and null values. The JVM does this when it creates the fields.

<init> is called, when an instance of the class is created. It must first initialize the super class, then other actions follow.

i: <init> ( -- )
     InitSuper ()
    <object init code>   ;

Example:   

i: <init> ( -- )
     InitSuper ()
     7 =: X  ;

The method <clinit> is called, when the class has been loaded into the JVM. 

: <clinit>  ( -- )
      <class init code>   ;

next

 

 

© 1999-2005 Wolf Wejgaard