gpt4 book ai didi

java - 编译器说有一个无法访问的语句,我做错了什么?

转载 作者:行者123 更新时间:2023-12-01 18:17:54 24 4
gpt4 key购买 nike

import java.io.File;

import java.io.IOException;

import java.util.Scanner;

class airport {

private static final String STDIN_FILENAME = "-";

public static treemap load_database (String database_name) {

treemap tree = new treemap ();

try {

Scanner database = new Scanner (new File (database_name));

for (int linenr = 1; database.hasNextLine(); ++linenr) {

String line = database.nextLine();

if (line.matches ("^\\s*(#.*)?$")) { continue;

//there is a problem with the below line

String[] keyvalue = line.split (":");

if (keyvalue.length != 2) {

misc.warn (database_name, linenr, "invalid line");
continue;
}
tree.put (keyvalue[0], keyvalue[1]);
}
database.close();
}
}
catch (IOException error) {
misc.warn (error.getMessage());
}
return tree;
}
}

最佳答案

if (line.matches ("^\\s*(#.*)?$")) { 
continue;
// unreachable code

执行不会超过继续。因此该 block 中它之后的所有内容都是无法访问的。

也许您想在继续之后关闭}

关于java - 编译器说有一个无法访问的语句,我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28535432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com