why is the following an illegal initialisation
java code:
String s[];
s = {"mmmmm","jjjjjj","nnnn"}
5 1166
why is the following an illegal initialisation
java code:
String s[];
s = {"mmmmm","jjjjjj","nnnn"}
You can have a look at the arrays entry in the JLS.
why is the following an illegal initialisation
java code:
String s[];
s = {"mmmmm","jjjjjj","nnnn"}
That's not initialisation, that's an assignment. Assignments go like this: -
s= new String[] { "aaa", "bbb", "ccc };
-
and initialisation goes like this: -
String[] s= { "aaa", "bbb", "ccc" };
-
kind regards,
Jos
that code is wrong because s is an array variable and to initialise arrays u use the array index which in java is index zero. got it.
String[] s = {"n", "u", "any"};
works because this indexing understood by your compiler but
s = {"n", "u", "any"}; will not be understood by your compiler because, 1. there is no index to signify this is an array, 2. if you index it this late, what index will the compiler look up for?
maybe try:
s[1] = "n";
s[2] = "u";
got it.
that code is wrong because s is an array variable and to initialise arrays u use the array index which in java is index zero. got it.
String[] s = {"n", "u", "any"};
works because this indexing understood by your compiler but
s = {"n", "u", "any"}; will not be understood by your compiler because, 1. there is no index to signify this is an array, 2. if you index it this late, what index will the compiler look up for?
maybe try:
s[1] = "n";
s[2] = "u";
got it.
It has nothing to do with indexes whatsoever. See my previous reply.
kind regards,
Jos
that code is wrong
...
No offense meant but like many of your replies, this one is again wrong. Perhaps it it a good thing to first check the things you post. You could've easily verified that there's nothing wrong with the line: - String[] array = {"Fu", "Bar"};
If you post something wrong, a beginning programmer might take your word for it and gets side tracked by your false claims.
If I post sometthing I'm not 100% sure of it is true, I either do not post it, or I tell the OP that I am not 100% sure about my claims. That way s/he knows to be carefull with the information provided.
Again: no offense meant.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tim |
last post by:
Please advise if you can.
Presumably initialisation of members in member initialisation lists is
perfomed by 'C' run-time startup. If the CRT was never started-up would
those members be garbage?...
|
by: John Carson |
last post by:
One routinely hears that the order of initialisation of objects with static
storage duration in different translation units cannot in general be
guaranteed. I have a question about one way to...
|
by: clilley |
last post by:
The following code causes a segmentation fault on DEC Tru64:
foo.cc (built into libFoo.so)
//---------------------------
include <iostream>
bool createFoo()
{
std::cout << "createFoo" <<...
|
by: Frederick Gotham |
last post by:
I have just been reading 8.5 in the Standard, and am trying to make sense
of the different kinds of initialisations.
Up until now, I thought of an object as either NOT being initialised (i.e....
|
by: Kevin Frey |
last post by:
I have an assembly written in C++/CLI that also links in non-clr Native C++
(the C++/CLI wraps the Native C++ functionality).
This assembly has an in-built tracing system that needs to be...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |