What does this line of code do?
I have tried testing it, but when I declared the methods as public and alter them within a class, it doesn't work, so I'm not sure how to inspect the objects:
int x = 5;
int xx[] =newint[]{x};//this is the one I'm unsure about
is it the same as:
int x = 5;
int xx[] =newint[x];
?
[677 byte] By [
abu5ea] at [2007-11-27 5:18:30]

> int xx[] = new int[]{x}; //this is the one I'm unsureAn int[] with a single element, whose value is x.> int xx[] = new int[x];An int[] with x elements, all of whose values are the default intiial value--0.
jverda at 2007-7-12 10:41:39 >

I did figure a way to try it, but it was confusing me by not allowing me to declare it within a method (I think I know why now). I wasn't being lazy - I did have BlueJ (for inspecting) open and I was trying it.
It seems to give me the same result as:
int xx[] = {x};
, but is there some subtle difference?
Message was edited by:
abu5e
abu5ea at 2007-7-12 10:41:39 >

> I did figure a way to try it, but it was confusing me
> by not allowing me to declare it within a method (I
> think I know why now). I wasn't being lazy - I did
> have BlueJ (for inspecting) open and I was trying
> it.
>
> It seems to give me the same result as:
> > int xx[] = {x};
>
, but is there some subtle difference?
Not in what it does, as far as I know.
You can only use the simple {x} form in a variable declaration like that. Other places, you have to use new int[] {x}.
jverda at 2007-7-12 10:41:39 >

> but is there some subtle difference?
nope. you can only use int xx[] = {x} when declaring a class or object
variable.
class x{
methods{ }
int xx[] = {};
}
where as int xx[] = new int[]{ } is a delightful shorthand for use inside
methods and the such.
I think this is what jverd was referring to. Just thought I would spell it out.
int[] y = {1,2,3,4}; // ok on one line
int[] x;
x = {1,2,3,4}; // error when not one one line