[問題] 不定長度引數造成的overflow
目前在練習不定常數引數的使用方法,
但照著書本打之後發現會出現
Exception in thread "main" java.lang.StackOverflowError
google過後發現有可能是過度呼叫函數的問題,
但小弟一直看不出哪裡有重複呼叫,不知道是不是可以麻煩版友們指點一下
小弟謝先!!!!
//////////////////////////////
class Calculator {
double price;
Calculator(double price) {
this.price = price;
}
double CalculatePrice(Land l) {
return l.area() * price;
}
double totalPrice(Land... Lands) {
double total = 0;
for (Land l : Lands) {
* total += totalPrice(l); //問題出現在此
}
return total;
}
}
public class poly {
public static void main(String[] argv) {
Circle c = new Circle(5);
Square s = new Square(5);
Calculator ca = new Calculator(3000.0);
System.out.println("總價值:" + // 使用匿名陣列
ca.totalPrice(new Land[]{c,s}));
}
////////////////////////////
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.117.164.141
→
09/13 12:38, , 1F
09/13 12:38, 1F
推
09/13 12:54, , 2F
09/13 12:54, 2F
推
09/13 12:57, , 3F
09/13 12:57, 3F
→
09/13 13:38, , 4F
09/13 13:38, 4F