我有一个方法public int bar()
,我在其中声明了一个int total
(在方法体 ofc 中)。所以这应该是一个简单的局部变量,问题是eclipse抱怨
Description Resource Path Location Type
The local variable total may not have been initialized Repository.java /proj_individual/src/repo line 35 Java Problem
一般示例:
public int foo(){
int total;
for(... : ...){
total += 1; // complains
}
return total;// complains
}
和我的确切代码:
public int getLocatars(){
int total;
for ( Map.Entry<Apartment, List<Expense>> entry : dic.entrySet() ) {
if(entry.getKey().isDebt()){
total += entry.getKey().getNrProple();
}
}
return total;
}
我不知道我做错了什么,所以任何想法都是有帮助的,谢谢。