Hello all,
I have a simple question regarding declare of veriables.
I have the following task:
if (type == "xx")
{
String[] yy = {"a", "b", "c"}; <--here I have a message(Local variable is never read)
}
else
{
String[] yy = {"d", "e", "f"};<--here I have a message(Local variable is never read)
}
So I need to declare an array depending on "type" value, but my arrays are not seen for future using.
Please help me with this question.
Thanks in advance!
Local variable is never read
Started by corsica, May 12 2010 01:46 AM
4 replies to this topic
#1
Posted 12 May 2010 - 01:46 AM
|
|
|
#2
Posted 12 May 2010 - 02:38 AM
Declare the array outside the if-else like
Variables only exist within the { } where they are declared in
String[] yy;
if (type == "xx")
yy = {"a", "b", "c"};
else
yy = {"d", "e", "f"};
Variables only exist within the { } where they are declared in
#3
Posted 12 May 2010 - 03:04 AM
Yes, I've tried such way, but I have the following error:
String[] yy;
if (type == "xx")
yy = {"a", "b", "c"}; <--Array constants can only be used in initializers
else
yy = {"d", "e", "f"};<--Error: Array constants can only be used in initializers
#4
Posted 12 May 2010 - 03:08 AM
Oops, my bad :)
String[] yy;
if (type == "xx")
yy = new String[] {"a", "b", "c"};
else
yy = new String[] {"d", "e", "f"};
#5
Posted 12 May 2010 - 03:21 AM
Thank you very much!
My problem is solved:)
My problem is solved:)


Sign In
Create Account

Back to top









