In Java, should variables be declared at the top of a function, or as they're needed?

前端 未结 12 1367
猫巷女王i
猫巷女王i 2020-12-02 13:09

I\'m cleaning up Java code for someone who starts their functions by declaring all variables up top, and initializing them to null/0/whatever, as opposed to declaring them a

12条回答
  •  -上瘾入骨i
    2020-12-02 13:52

    Its a matter of readability and personal preference rather than performance. The compiler does not care and will generate the same code anyway.

提交回复
热议问题