我有一个关于 java 上的 try catch 的 n00b/basic 问题。
Ini myIni;
try {
myIni = new Ini(new FileReader(myFile));
} catch (IOException e) {
e.printStackTrace();
}
myIni.get("toto");
and the error message that follows : variable myIni might not have been initialized
try的范围是否仅限于try区? 如何在以下代码中获取 myIni 的结果?
最佳答案
为了避免该消息,您需要在try语句之前设置一个默认值。
或者您需要在 try 语句中调用 get()
方法。
关于java - try catch 语句的范围问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7599941/