在哪里初始化字段更好?在构造函数(var.1)或声明(var.2)中?
变种。1
public class UtilWebLoading {
private int data;
private Context context;
public UtilWebLoading(Context context) {
this.context = context;
data = 100;
}
...
}
变种。2
public class UtilWebLoading {
private int data = 100;
private Context context;
public UtilWebLoading(Context context) {
this.context = context;
}
...
}