gpt4 book ai didi

java - try catch 语句的范围问题

转载 作者:搜寻专家 更新时间:2023-10-31 08:18:01 24 4
gpt4 key购买 nike

我有一个关于 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/

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