Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Quick Java syntax question

Options
  • 14-05-2009 12:15pm
    #1
    Subscribers Posts: 6,408 ✭✭✭


    When passing arrays as parameters to methods what is the correct or "standard" syntax to use?
    public static void main(String args[])
    

    does the same as
    public static void main(String[] args)
    

    and
    public static int[][] copy2dArray(int other2dArray[][]){
    

    does the same as
    public static int[][] copy2dArray(int[][] other2dArray){
    


    I noticed that I tend to put the square brackets as part of the type declaration because it just seems more logical. The type is "array of String" not "String" and "array of array of int" not "int"

    Am I wrong, should I stick to the "normal" way or am i making a huge deal out of nothing! :)


Comments

  • Registered Users Posts: 1,998 ✭✭✭lynchie


    Both are the same. An array declaration can either follow the variable name or the type.. Do whatever your comfortable with. Though I think Sun's convention is String argv[] as opposed to String[] argv


  • Subscribers Posts: 6,408 ✭✭✭conzy


    okee doke thanks


  • Registered Users Posts: 1,916 ✭✭✭ronivek


    You're probably making a big deal out of nothing alright but yes; as the type is "an array of type" then generally speaking type[] makes more sense semantically.


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Most important is to be self-consistent. Use the same notation-style throughout your code. In an ideal world, have a "style guide" which declares decisions like this.


Advertisement