Java array convention: String[] args vs. String args[]

后端 未结 4 1766
孤城傲影
孤城傲影 2020-12-08 20:49

I am currently teaching students as a tutor programming conventions. I\'ve told them that they can find most conventions in the Oracle Code Conventions.

In my last

4条回答
  •  旧巷少年郎
    2020-12-08 21:20

    Oracle's Code Conventions do not explicitly state it, but in all examples they use the brackets immediately after the declared type.

    In their example code (which should be considered authoritative in this context) they use:

    private Object[] instanceVar3;

    Also on the page detailing the initialization of variables they have this example that demonstrates the possible problems of putting the brackets behind the variable name:

    int foo, fooarray[]; //WRONG!

    One could be tempted to do this and think one were declaring several arrays. Althoug this syntactically correct (as brimborium pointed out in the comments), Oracle didn't put the capital letters there for nothing. Better to be safe, clear and also type less by putting the brackets behind the type to show clearly what you want to declare.

提交回复
热议问题