編譯器指出語句在if
語句的行中無法訪問。我不太熟悉Java。爲什麼說我的If語句無法訪問?
public double calculate()
{
total_usage_charge = getUsageCharge();
total_charge = rate + total_usage_charge;
return total_charge;
if("A".equals(package_plan.toUpperCase()) && getUsageCharge() > 14.95)
{
sB = getUsageCharge() - 14.95;
System.out.println("You're spending more money than you should. If you switched to Plan B you would save:$" + sB);
}
}
我刪除了幫助案例和其他混亂。請嘗試刪除不需要的代碼以幫助我們(和您!)專注於實際問題。 – 2013-03-19 08:07:15
如果編譯器說某些語句不可訪問意味着在代碼執行過程中無法達到聲明。編譯器可以在編譯期間發現一些無法訪問的代碼(例如:在last語句之前返回,if(false){statement}等) 但要小心,因爲編譯器無法找到所有情況,因爲程序執行路徑取決於先前執行的所以你必須注意 – pedjaradenkovic 2013-03-19 08:13:02