1
我有這段代碼,我必須避免DD異常「最近變量被重新定義」。但是我必須避免創建另一個返回語句。我不知道如何去做。如果任何人都可以幫助我,這將是非常有益的。避免DD異常而不添加return語句
代碼DD異常
public static boolean hasActiveInternetConnection() {
int returnVal = 1;
try {
final Process ping = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com");
returnVal = ping.waitFor();
} catch (final java.io.IOException | InterruptedException e) {
Log.e(TAG, e.getMessage());
}
return returnVal == 0;
}
代碼雙倍返還異常
public static boolean hasActiveInternetConnection() {
try {
final Process ping = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com");
final int returnVal = ping.waitFor();
return returnVal == 0;
} catch (final java.io.IOException | InterruptedException e) {
Log.e(TAG, e.getMessage());
}
return false;
}
謝謝!
爲我工作,我很欣賞它 關心 –