1

im migrating a project from c# to java java but there is something in a class constructor that i dont understand ..

here is the code

public FacTextBlock (FacRegion region, string text, FacFont font) : base (region, new FacBlock [0])
        {
            
               int          cleanCount = 0;
            
               for (int i = text.Length - 1; i > -1; i --)
               {
                  if (text [i] == 8232)
                     cleanCount ++;
                  else
                    break;
               }

               if (cleanCount != 0)
                  text = text.Substring (0, text.Length - cleanCount);
            // Filtrer : '[' et ']'.
               List<char>       filtredChars = new List<char> ();

                foreach (char c in text)
                {
                if (c != '[' && c != ']')
                    filtredChars.Add (c);
                }

                text = new string (filtredChars.ToArray ());
                // Continuer.
                this._Text = text;
                this._Font = font;
           }

        public FacTextBlock (FacTextBlock [] textBlocks) : this (FacBlock.GetRegion (textBlocks), FacTextBlock._GetMergedText (textBlocks), textBlocks [0].Font)
        {
            FacDocument     document = textBlocks [0].Document;
            if (document != null)
                this.__Document = document;

            this._IsVirtual = true;
        }

(i cant post a lot of code so i try to explain)

okey these are two construtors of FacTextBlock class that inherit a class called Block

for the first one : base() its calling the parent class constructor in java it can be done with super()

but my problem is the 2nd constructor i can't understand what does :this (FacBlock.GetRegion (textBlocks), FacTextBlock._GetMergedText (textBlocks), textBlocks [0].Font) mean ? when i do (Ctrl+click on this ) it takes me to the first constructor , is it calling the first constructor ??? and how can i write this in java ?

1 Answers1

0

This is constructor chaining. You can do it in Java the same way you called super().

SomeObject(int a, int b) {
    this.a = a;
    this.b = b;
}

SomeObject(int a) {
    this(a,0);
}
swpalmer
  • 3,890
  • 2
  • 23
  • 31