Java无法访问的语句

tes*_*est 2 java arrays

我正在尝试编写一个方法,根据loadBoard(NUMBER_HERE)中的数字加载地图; 但我在线上得到了"无法达到的声明"

return board;
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

public int[][] loadBoard(int map) {
    if (map == 1) {   return new int[][] { 

 {2,2,24,24,24,24,24,3,3,0,0,0,1 },

 { 2,2,24,23,23,23,24,1,3,0,0,0,1 },

 { 1,1,24,23,23,23,24,1,3,3,3,3,1 },

 { 1,1,24,24,23,24,24,1,1,1,1,3,1 },

 { 1,1,1,1,7,1,1,1,1,1,1,3,1 },

 { 5,1,1,1,7,7,7,7,7,1,1,1,1 },

 { 6,3,3,1,3,3,3,1,7,7,7,3,1 },

 { 6,3,3,1,3,1,1,1,1,1,7,1,1 },

 { 3,3,1,1,1,1,1,1,1,1,7,1,1 } };

 }else{

 return new int[][] {

 { 1,1,1,1,1,24,1,1,1,1,1,1,1 },


 { 1,1,1,1,1,24,1,1,1,1,1,1,1 },

 { 1,1,1,1,1,24,1,1,24,1,1,1,1 },

 { 1,1,1,1,1,24,1,1,24,1,1,1,1 },

 { 1,1,7,1,1,24,24,24,24,1,1,1,1 },

 { 1,1,7,1,1,24,1,24,1,1,1,1,1 },

 { 1,1,1,1,1,24,1,1,1,1,1,1,1 },

 { 1,1,1,1,1,24,1,1,1,1,1,1,1 },

 { 1,3,3,1,1,24,1,1,1,1,1,1,1 },

 }; } 

 return board;  }
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Mat*_*ell 7

你的最后一行 return board;

如果你查看你的代码,你有:

if (condition)
  return /* Some things go here */
else
  return /* The rest go here */
return /* But who goes here? */
Run Code Online (Sandbox Code Playgroud)

答案是删除那Unreachable行代码,因为它实际上毫无意义.