我有一個方法使用類Region中的對象,因爲我需要掃描該對象的另一個方法使用此方法,因此我可以應用該方法。Java掃描對象
public void changeBusinessPermitTile(Region region){
if(getRegion()==null) {
Region i;
Scanner scanner = null;
try {
System.out.print("Please insert the region: ");
scanner = new Scanner(System.in);
i = scanner.//this is the missing part
setRegion(i);
} finally {
if (scanner!=null)
scanner.close();
}
}
}
所以我想的是,當我寫例如
Region region1 = new Region(Landscape.COAST);
Region region2 = new Region(Landscape.HILL);
Region region3 = new Region(Landscape.MOUNTAIN);
這種方法應該能夠掃描當我寫REGION1,區域2或區3
你會希望避免關閉,除非你的整個程序是使用'System.in'做到這一點已經被初始化的'System.in'掃描儀。 –
所以我只壓制警告'資源泄漏:'掃描儀'永遠不會關閉'? – mpz
此外,您的代碼看起來像可能將業務邏輯與用戶界面混合在一起。如果可能的話,這兩者應該分開放置。 –