This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Component Arrays

 
Tetsuo Suzuki
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ran into something a bit strange; if I have a component array it won't allow me to initialize each component outside of the constructor. An example of what I mean:

But...

Is assigning the 'new' keyword here doing something executable that can't be in declaration?
Thanks much,
Tetsuo!
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tetsuo,
You are not seeing something a little strange. You are seeing how java works!
An assignment (to any variable) can be done in two ways:
1) Along with declaration:

2) Inside any code block (defined by braces {}):

Java will not let you perform assignments outside code blocks with the exception of number 1 above.
Regards,
Manfred.
[ March 14, 2002: Message edited by: Manfred Leonhardt ]
 
Colin Humber
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JLabel[] x={new JLabel("Label1"),
new JLabel("label2")};
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic