public void getBenjin() {
if (null != benjin.getText()) {
benjinD = Double.parseDouble(benjin.getText().toString());
}
}
public void getLilv() {
if (null != lilv.getText()) {
lilvD = Double.parseDouble(lilv.getText().toString());
};
}
public void getShijian() {
if (null != shijian.getText()) {
shijianI = Integer.parseInt((shijian.getText().toString()));
};
}
和
public void getNumber() {
if (null != benjin.getText()) {
benjinD = Double.parseDouble(benjin.getText().toString());
}
if (null != lilv.getText()) {
lilvD = Double.parseDouble(lilv.getText().toString());
};
if (null != shijian.getText()) {
shijianI = Integer.parseInt((shijian.getText().toString()));
};
}
功能上沒什麼區別,上一種方法是分別初始化了三個變量,下一種方法是集中處理。但是個人感覺if語句後面是不用加空語句的。