Initializing two-dimensional arrays

Hi,

I'm having problems initializing two-dimensional arrays in template declarations. I want to write the following

Matrix m = new Matrix[][] { {1,2}, {3,4} }

but I can't insert the nested curly brackets. I create the 2d Matrix array by first creating an array with initializer, and then use the intention list to convert the Matrix to an array type. How can I add the nested brackets?

Cheers,

Rob

2 comments
Comment actions Permalink

Hey Rob,

I don't know if this is the only way, but one way you can do it is like so:

Matrix[][] abc = new Matrix[][]{ new Matrix[]{1, 2}, new Matrix[]{3, 4} };

It's a little more long-winded, but I think that should work just fine.

Hope this helps!

(another) Robert

0
Comment actions Permalink

Hello, Rob,

Unfortunately, It's now impossible to initialize an array the way you want. The only way is to nest array initializers with new expressions. I created a request in our tracker http://www.jetbrains.net/tracker/issue2/MPS-5264

Regards,

Konstantin

0

Please sign in to leave a comment.