Java coding convention about static method

前端 未结 7 633
情深已故
情深已故 2021-02-05 16:24

It is a very simple question, but I think it is a little bit controversial.

When I code Java classes I use the following order.

class Foo {

    // stati         


        
7条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 17:13

    The Java Code Conventions suggest the following (which is basically what you already do):

    • Class (static) variables: First the public class variables, then the protected, then package level (no access modifier), and then the private
    • Instance variables: First public, then protected, then package level (no access modifier), and then private
    • Constructors
    • Methods: These methods should be grouped by functionality rather than by scope or accessibility. For example, a private class method can be in between two public instance methods. The goal is to make reading and understanding the code easier.

提交回复
热议问题