【问题标题】:what is the advantage of initializing variables in the constructor of a Java class in Android? [duplicate]在Android中Java类的构造函数中初始化变量有什么好处? [复制]
【发布时间】:2013-06-16 17:25:53
【问题描述】:

下面展示了两个android类的例子,它们是不扩展Activity的实用类。

使用示例 1 有什么优势,为什么比示例 2 更好?

示例 1

public class SKR {

String[] code;
String[] sub_code;

public SKR(){

    code = new String[87];
    sub_code = new String[87];

    }

}

示例 2

public class SKR {

String[] code = new String[87];
String[] sub_code = new String[87];

    public SKR(){


   }

}

【问题讨论】:

标签: java android constructor helper


【解决方案1】:

我认为第二个更好,以便编译器可以预编译代码。

但代码并没有真正的区别。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多