0
아래에 안드로이드 클래스의 두 가지 예가 나와 있습니다.이 클래스는 Activity를 확장하지 않는 유틸리티 클래스입니다.안드로이드에서 Java 클래스의 생성자에서 변수를 초기화 할 때의 이점은 무엇입니까?
예 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(){
}
}
http://stackoverflow.com/questions/3918578/should-i-initialize-variable-within-constructor-or-outside-constructor 및 http://stackoverflow.com/questions/24551/best-practice -initialize-class-fields-in-constructor-or-at-declaration – jprofitt