如下代码:
public static void print(ListNode p)
{
System.out.print("[");
if(p==null);
{
System.out.println("]");
return;
}
ListNode k = p.getNext();
//more code
}
导致以下编译错误:
----jGRASP exec: javac -g Josephus_5_Rajolu.java
Josephus_5_Rajolu.java:53: error: unreachable statement
ListNode k = p.getNext();
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
为什么会这样呢?
我只在p = null时返回。如果p!= null,我想做其他代码。为什么无法访问?
最佳答案
if
语句后有分号。