There is no difference, both are legal declarations of the main() method. In String args, args is nothing but an array of type String and holds the arguments you pass to your program at runtime. An array can be legally declared as follows,
in this context, i would like to ask abt varargs in functions as the 1.5 ver gave this option but it is only to the last arg. is it not convinent top have the option for allt he argumennts instead of the last? is there any other option for this?
I just started a Java class and my instructor mentioned the second approach is preferred, BUT... I have to agree that using the first approach for defining an array (int = int) that one can very quickly see the variable is an array w/o having to read the entire line of code.
Thank you very much.
author and iconoclast
Originally posted by Barb Rudnick: my instructor mentioned the second approach is preferred,.
It's just a matter of taste, but the second approach is the "old" style syntax inherited from C/C++, and the first approach (i.e., "int x") is the idiomatic Java way. I've never seen a Java programmer who preferred the second approach, so I think your instructor's tastes are somewhat out of the mainstream.
Joined: Oct 30, 2005
Quote: xplain to me how these would work:
int whatDoesThisDo(String... x, String... y) ... int orThis(int... x, Integer... y) ... int orEvenThis(double... x, Float... y) ...
i.e., what are the values of x and y if I say:
I understand it, however, the datatypes can be different like: the second and third ones.
Joined: Sep 16, 2005
Originally posted by Sam Francis: I understand it, however, the datatypes can be different like: the second and third ones.
Beware the autobox my son. The following is perfectly legal:
So allowing a method like void f(Integer...a, int...b) sounds problematic. I think Java hit the sweet spot, a nice light snack of syntactic sugar.
Originally posted by Jim Yingst: [b] They wouldn't. You can only have one ... in a method signature, and you may not have any other arguments after it.
You missed the hypothetical, Jim -- he was asking why only the last argument was allowed to have an ellipsis.
Joined: Jan 30, 2000
Ah, I misread the funky quoting style, and the response formatted like a signature for some reason. And I didn't read the preceding thread closely enough because I assumed that any questions prior to EFH's last post had already been answered completely. [ November 03, 2005: Message edited by: Jim Yingst ]