Results 1 to 3 of 3
  1. #1
    gcampton Guest

    Default Why doesn't main use varagrs?

    I was curious as to why the default main does not use varargs. Unlike other languages and scripting languages the first position of arguments (the zeroth element) does not reference the program name/package/jar
    So I really I would think it would have been better to implement main in the format of:

    Java Code:
    public class foo
    {
        public static void main(String... args)
        {
            // TODO stuff with args if they exist....
        }
    }
    The above code compiles and runs naturally, I guess the question is kind of pointless as varargs and an array are pretty much the same thing. But it seems a bit funny to me why have an array as convention when varargs is more suited for situations where you don't know if there will be zero, 1 or multiple args.
    Last edited by gcampton; 01-19-2010 at 03:27 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    So, ask yourself a question: when were varargs introduced into Java? In the beginning?

    Hint: look here

  3. #3
    gcampton Guest

Similar Threads

  1. Replies: 6
    Last Post: 07-16-2009, 03:30 PM
  2. Replies: 1
    Last Post: 07-16-2009, 10:35 AM
  3. Replies: 5
    Last Post: 10-06-2008, 12:11 AM
  4. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. Replies: 1
    Last Post: 08-06-2007, 09:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •