|
-
Dec 25th, 2002, 03:26 PM
#1
Initializing arrays.
I have a class which contains a 2-d boolean array as private member. The class also contains a static array of 7 instances of the class, the only instances that will ever exist. And I have a static block to create that array:
Code:
class TetrisBlock
{
private boolean[][] blockLook;
private TetrisBlock()
{
}
private static TetrisBlock[] blocks;
static {
blocks = new TetrisBlock[7];
blocks[0] = new TetrisBlock();
blocks[0].blockLook = { { true, true, true, true}, // ####
{false, false, false, false} }; // ----
blocks[1] = new TetrisBlock();
blocks[1].blockLook = { { true, true, true, false}, // ###-
{ true, false, false, false} }; // #---
blocks[2] = new TetrisBlock();
blocks[2].blockLook = { { true, false, false, false}, // #---
{ true, true, true, false} }; // ###-
blocks[3] = new TetrisBlock();
blocks[3].blockLook = { {false, true, true, false}, // -##-
{ true, true, false, false} }; // ##--
blocks[4] = new TetrisBlock();
blocks[4].blockLook = { { true, true, false, false}, // ##--
{false, true, true, false} }; // -##-
blocks[5] = new TetrisBlock();
blocks[5].blockLook = { {false, true, false, false}, // -#--
{ true, true, true, false} }; // ###-
blocks[6] = new TetrisBlock();
blocks[6].blockLook = { { true, true, false, false}, // ##--
{ true, true, false, false} }; // ##--
}
The compiler says this code is not correct. It gives me the following error:
TetrisBlock.java:17: illegal start of expression
blocks[0].blockLook = { { true, true, true, true}, // ####
It gives me the same error for all similar lines.
What am I doing wrong? Isn't this the way to directly initialize arrays?
Thanks in advance.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|