migrating c# to java : constructor () : this



我正在将一个项目从c#迁移到Java Java,但是在类构造函数中有一些东西我不理解…

代码

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;
}

(我不能张贴很多代码,所以我试着解释)

好的这是FacTextBlock类的两个构造函数它们继承了Block

类对于第一个: base(),它在java中调用父类构造函数可以使用super()

但我的问题是第二个构造函数,我不能理解:this (FacBlock.GetRegion (textBlocks), FacTextBlock._GetMergedText (textBlocks), textBlocks [0].Font)是什么意思?当我这样做(Ctrl+点击这个)它带我到第一个构造函数,它是调用第一个构造函数吗??我怎么用Java写这个呢?

这是构造函数链。您可以在Java中使用与调用super()相同的方法。

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

相关内容

最新更新