作者superlubu (劲过吕布)
看板java
标题Re: [问题] If else & return 的问题
时间Wed Jun 6 10:01:49 2007
※ 引述《rockcen (杰)》之铭言:
: 写了两个需要return的method
: 为什麽第二个在compile的时候
: 会要求return值, 第一个确不会呢?
: 在我眼里是一样的@@
: 请教一下!非常感谢!
: 2.
: public char pop(){
: if(top == -1)
: System.out.println("Stack是空的");
: else
: return stack[top--];
: }
因为当 top == -1 的时候它只会跑 "System.out.println("Stack是空的");"
然後没有任何 return statement 会执行到,所以 compiler 会告诉你要传回值
而第一个 method 中所有 if... else... 都有 return statement 所以没有问题.
--
劲过吕布的劲过相薄...
http://www.wretch.cc/album/superlubu
乱七八糟的,不好意思 m(_ _)m
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 147.8.130.225
※ 编辑: superlubu 来自: 147.8.130.225 (06/06 10:02)