File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question about arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A question about arrays" Watch "A question about arrays" New topic

A question about arrays

Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Hi all!
Take a look at the following code:

Now - I know you get an error when you try to intialize the arrays e and f. But I havn't found any explenation for it. If we take a look at array b and e, then the way they intialize the arrays look rather similar.
Does anyone know why this isn't possible ?
Thanks in advance
/Svend Rost
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
The simple answer would be to say that this is because the grammar of the Java language does not allow an array initializer to appear anywhere else than after an array declaration (or creation) expression.
Please check out JLS 10.6 Array Initializers and JLS 15.10 Array Creation Expressions

[Blog] [Blogroll] [My Reviews] My Linked In
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Thanks for the quick answer
I'll dig right into it.
/Svend Rost
I agree. Here's the link:
subject: A question about arrays
It's not a secret anymore!