try/catch 的范围是什么?本质上,我正在反序列化一些对象并创建新的引用来存储它们。加载它们后,我尝试在引用中使用一种方法,但出现以下编译错误。
try{
ObjectInputStream is = new ObjectInputStream(new FileInputStream("saveGame.ser"));
gameCharacter oneRestore = (gameCharacter) is.readObject();
gameCharacter twoRestore = (gameCharacter) is.readObject();
gameCharacter threeRestore = (gameCharacter) is.readObject();
} catch (Exception ex) {ex.printStackTrace();}
System.out.println("One's type is: " + oneRestore.getType());
System.out.println("Two's type is: " + twoRestore.getType());
System.out.println("Three's type is: " + threeRestore.getType());
编译错误是:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
oneRestore cannot be resolved
twoRestore cannot be resolved
threeRestore cannot be resolved