This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
svdragster's profile picture

[Java] Multiple vars in one line

Started by svdragster, 09 July 2013 - 01:56 PM
svdragster #1
Posted 09 July 2013 - 03:56 PM
Hey, does anyone know if something like this is possible in Java, too?

x, y, z = 4, 64, 4
ETHANATOR360 #2
Posted 09 July 2013 - 04:01 PM
why not assign them like this?

int x = 4,y = 64, z = 4;
GopherAtl #3
Posted 09 July 2013 - 04:01 PM
You can if they're all the same type, the syntax is…

 int x=4, y=64, z=4;
Mads #4
Posted 10 July 2013 - 03:43 AM
Provided they're all the same value and type, you can also do shit like

int x = y = z = 4;
nolongerexistant #5
Posted 10 July 2013 - 04:09 AM
Provided they're all the same value and type, you can also do shit like

int x = y = z = 4;

You actually can't do it like that. Y and Z are undefined and that will error
Mads #6
Posted 10 July 2013 - 04:52 AM
Wasn't it introduced in 1.7?
nolongerexistant #7
Posted 10 July 2013 - 04:57 AM
I always have the latest version of Java and my Eclipse errors:


Multiple markers at this line
- z cannot be resolved to a
  variable
- y cannot be resolved to a
  variable
Engineer #8
Posted 10 July 2013 - 09:26 AM
http://puu.sh/3zrBv.png ?

Show us your code please
Tiin57 #9
Posted 10 July 2013 - 10:58 AM
I thought it was

int x, y, z = 2;
Mads #10
Posted 10 July 2013 - 11:45 AM
I thought it was

int x, y, z = 2;
That would declare all three, but leave x and y un-initialised.
nolongerexistant #11
Posted 11 July 2013 - 06:15 AM
http://puu.sh/3zrBv.png ?

Show us your code please