小编mit*_*_au的帖子

Java最佳实践 - 在类变量之前声明构造函数是一件坏事吗?

我正在从一位同事(另一位学生)那里进行Java代码的"静态"代码演练

对我来说,这没有意义; 从上到下阅读这些"组件"对象在声明之前进行实例化(稍后在构造函数中使用).但是,代码很乐意编译并运行.这是不好的做法吗?

Public Class theObject {

    private static final long aVariable = 123123123123123;

    public theObject(...){

        componentOne = new Component(...);
        componentTwo = new Component(...);

        ...
        ...
        componentOne.doSomething(...);
    }

    private Component componentOne;
    private Component componentTwo;
}
Run Code Online (Sandbox Code Playgroud)

java coding-style

10
推荐指数
4
解决办法
2万
查看次数

标签 统计

coding-style ×1

java ×1