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

时间:2015-02-16 06:06:23

标签: java

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;
            }
        }

1 个答案:

答案 0 :(得分:4)

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

执行不会超过continue。因此,该块中的所有内容都无法访问。

也许您想在}之后关闭continue