Well since its a postincrement, you return before it will be incremented or?
however in case of the finally it would be a preincrement, so it would be before or?
Who can guess what will happen if I try to use this?
[java]
/**
Generated by the IBM IDL-to-Java compiler, version 1.0
from F:\TestRoot\apps\a1\units\include\PolicyHome.idl
Wednesday, June 17, 1998 6:44:40 o’clock AM GMT+00:00
*/
public class Test {
public static void main(String[] args) {
System.out.print(“Hell”);
System.out.println(“o world”);
}
}
[/java]
since the increment gets executed after all other operations in that expression. That was the part that made me belive the above code would return 1.
As stack:
return i++;
is like:
push i
i=i+1
return i
pop i
//Edit: actually it probably is:
return i
push i
i=i+1
pop i
but then i don’t see why finally executes the expressions after the return
You are confused.
I wrote:
return i++
is like:
push i
i = i + 1;
pop value
return value
So,
push 0
i = 0 + 1
pop 0
return 0
Return is LAST… after everything. You have to have done everything before returning because no code is executed after the turn.
The return causes the finally block to execute and since you have a different return it is not returning a value based on the NEW value of i… because that code already ran before the return. For a block, return is always last. Nothing can run after it because control flow has already gone elsewhere.
[java]
public class CompareTest
{
public static void main(String args[])
{
float a = 0;
float b = 0;
a += 0.7;
b += 0.5;
if (a < 0.7) {
if (b < 0.5){
System.out.println(“Both smaller”);
}else{
System.out.println(“One smaller”);
}
}else{
System.out.println(“None smaller”);
}
}
}