Trying to use this() in a constructor, not the first line

I'm currently re-writing some old code of mine that was used to create a neural network. My main contructor, originally, was

public Network(int sizeLayer1,int sizeLayer2,int sizeLayer3)

Now, however, I've decided that I want to make my network a little more general, and allow any number of layers. Therefore, my revised basic constructor is

public Network(int[] sizeLayers)

which expects an array of ints corresponding to the size of each layer.

However, I've got some old programs that use the old contructor which I can't change (and anyway, it's good to have the option to be able to use both). I therefore want to create a constructor that has the same signature as the old one, but simply places the values in an array and passes the array to the new constructor.

public Network(int sizeLayer1,int sizeLayer2,int sizeLayer3){

int[] sizeLayers ={sizeLayer1, sizeLayer2, sizeLayer3};

this(sizeLayers);

}

obviously won't work, because 'this' must be the first line of the constructor. How can I put my values in an array and call the new constructor?

Thanks!

[1651 byte] By [Asbestosa] at [2007-10-3 3:29:57]
# 1
this(new int[] {sizeLayer1, sizeLayer2, sizeLayer3});~
yawmarka at 2007-7-14 21:23:47 > top of Java-index,Java Essentials,New To Java...
# 2

Silly me -- I had been trying to do

this({sizeLayer1, sizeLayer2, sizeLayer3});

but of course that wouldn't work.

Thank you very much for that reply!

However, more generally, what if I wanted to do a few lines of processing on the variables passed, like adding them together before calling this()? Is there no way to do that? What's the purpose of requiring that this() be the first line in the constructor?

Thanks!

Asbestosa at 2007-7-14 21:23:47 > top of Java-index,Java Essentials,New To Java...
# 3
write an init method and call that in the ctor instead."What's the purpose of requiring that this() be the first line in the constructor?" - language requirement.%
duffymoa at 2007-7-14 21:23:47 > top of Java-index,Java Essentials,New To Java...
# 4
> write an init method and call that in the ctor> instead.Ok, that makes sense. Thanks.
Asbestosa at 2007-7-14 21:23:47 > top of Java-index,Java Essentials,New To Java...