Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些代码,就这个问题而言,相当于
final int n; try { n = someFunctionThatThrowsMyException(); } catch (MyException e){ n = 4; }
但是 NetBeans 在 catch 块中发出错误“变量 n 可能已被分配”。
真的是这样吗?我在这里想念什么?
你不能。你需要做这样的事情:
final int n; int temp; try { temp = someFunctionThatThrowsMyException(); } catch (MyException e){ temp = 4; } n = temp;