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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Quick Java syntax question

  • 14-05-2009 11:15am
    #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, Registered Users 2 Posts: 2,013 ✭✭✭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, Registered Users 2 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, Registered Users 2 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