1. What is the effect of not capturing the value of a method that returns a value?
The effect really doesn't work.
The return value will be calculated, and if it was created on the heap (as in the first example), it will immediately have the right to garbage collection.
In your second example, the return value will end on the stack and will simply be discarded after the method returns.
2. , , .
, . , .
, :
public class Test {
public static int testMethod() {
return 5;
}
public static void main(String[] args) {
testMethod();
}
}
... -:
public static int testMethod();
Code:
0: iconst_5
1: ireturn
public static void main(java.lang.String[]);
Code:
0: invokestatic #2;
3: pop
4: return
}