Variable not initialized in try catch block `finally`

Why does the compiler not understand that a variable is initializing in a block tryor catch complaining about a block finally?

int i;
try {
    i = 0;
}
catch (Exception e) {
    i = 2;
}
finally {
    System.out(i);
}
+4
source share
3 answers

"i" catch , , , , "i" try, "i" , , , , .. "i" , , , "i" catch, "i"

, try, catch. , , . (, , ) , . :

    int i;
    try {
        System.out.println(i);
        //i = 0;
    }
    catch (Exception e) {
        System.out.println(i);
        //i = 2;
    }
    finally {
        System.out.println(i);
    }
+2

(i = 0;) , finally, - , .

+5

, i . - , finally .

+2

All Articles