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

前端 未结 12 1420
猫巷女王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条回答
  •  情话喂你
    2020-12-02 13:38

    I've seen people declare at the top and at the bottom of functions. I prefer the top, where I can see them quickly. It's a matter of choice and preference.

提交回复
热议问题