我有一个方法public int bar(),其中我声明了一个int total(在方法体ofc中)。所以这应该是一个simpel局部变量,问题是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;
}我不知道我可能做错了什么,所以任何想法都是有帮助的,谢谢。
发布于 2012-11-27 01:44:34
https://stackoverflow.com/questions/13570222
复制相似问题