G
Guest
Hi !
I wonder if one of you nice java experts could help me with a real
quick question.
I am unable to get the code in 'FAILS TO COMPILE' (in the function
below to work... well actually i have simple workaround... But this
really started to annoy me. There's probably some subtle Java point
i'm missing (or worse... maybe there's an eclipse bug?).
anyway... if someone could tell me what the root of the problem might
be, I'd be most grateful.
CODE:
void bizzare()
{
String[] sfoo = { "boo", "zoo"};
Object o = sfoo; // String[] can be assigned to an Object
final Object[][] good = {
{"foo", sfoo },
{"bar", sfoo }
};
// FAILS TO COMPILE.. not sure why
// final Object[][] expected = {
// {"foo", (Object){ "boo", "zoo"} },// Casting fails
// {"bar", { "boo", "zoo"} } // so does not casting.
// };
//
}
FINALLY... my work-around:
void workAround()
{
final Object[][] good = {
{"foo", new String[] { "boo", "zoo"} },
{"bar", new String[] { "boo", "zoo"} }
};
}
thanks in advance for any advice / help you can spare....
/ chris
I wonder if one of you nice java experts could help me with a real
quick question.
I am unable to get the code in 'FAILS TO COMPILE' (in the function
below to work... well actually i have simple workaround... But this
really started to annoy me. There's probably some subtle Java point
i'm missing (or worse... maybe there's an eclipse bug?).
anyway... if someone could tell me what the root of the problem might
be, I'd be most grateful.
CODE:
void bizzare()
{
String[] sfoo = { "boo", "zoo"};
Object o = sfoo; // String[] can be assigned to an Object
final Object[][] good = {
{"foo", sfoo },
{"bar", sfoo }
};
// FAILS TO COMPILE.. not sure why
// final Object[][] expected = {
// {"foo", (Object){ "boo", "zoo"} },// Casting fails
// {"bar", { "boo", "zoo"} } // so does not casting.
// };
//
}
FINALLY... my work-around:
void workAround()
{
final Object[][] good = {
{"foo", new String[] { "boo", "zoo"} },
{"bar", new String[] { "boo", "zoo"} }
};
}
thanks in advance for any advice / help you can spare....
/ chris