java - How to define multiple variables in single statement -


in python, can define 2 variables array in 1 line.

>>>[a,b] = [1,2] >>>a 1 >>>b 2 

how do same thing in java?

i have couple of variables in class pct type final. there way define them in 1 line in python fashion? following format not work in java. define them separately, call parsefile method twice want avoid.

public class pct {     final int start;     final int stop;     public pct (file file) {         //......         //......         // following statement not compile         [start, stop] = parsefile(file);     }     public int[] parsefile(file f) {         int[] aa = new int[2];         // ....         // ....         return aa;     } } 

this not possible, don't need call parsefile twice.

write code this:

int [] temp = parsefile(file); start = temp[0]; stop = temp[1]; 

python (i believe) supports multiple return values. java obeys c conventions, , doesn't permit it. since isn't part of language, syntax isn't either, meaning gross hacks temp array needed if you're doing multiple returns.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -