Questions tagged [effectively-final]
7 questions
103
votes
2 answers
Effectively final vs final - Different behavior
So far I thought that effectively final and final are more or less equivalent and that the JLS would treat them similar if not identical in the actual behavior. Then I found this contrived scenario:
final int a = 97;
System.out.println(true ? a :…

Zabuzard
- 25,064
- 8
- 58
- 82
2
votes
1 answer
why resources declared outside the try-with-resources statement need to be final or effectively final in java?
why resources declared outside the try-with-resources statement need to be final or effectively final in java? ex: why object_name in the below code needs to be final or effectively final?
type object_name = new type();
try (object_name) {
...
}

mayank mahajan
- 61
- 1
- 4
2
votes
1 answer
How can I avoid complie error "lambda expression should be final or effectively final", if I want to apply different actions under different state?
For example I have two simple as possible classes, A and B
I want to take some action on objects of B, if some specific field of A object is changed I should do one thing, If some other field is changed I should do second thing, how can I do that…

DozezQuest
- 179
- 7
1
vote
1 answer
Can instance variables be effectively final / Are only local variables effectively final in Java?
I want to use try-with-resources enhancement in Java 9 by putting reference variable inside try with resources instead of the entire variable declaration. I also know that to do that I must follow rule: Variable used as a try-with-resources resource…

Stefan
- 969
- 6
- 9
0
votes
0 answers
Why does my integer need to be final or effectively final?
So I'm making a simple version of bloons tower defense and I was making a method for the path that the balloons will follow, but it kept telling me that integer than I declared in the method needed to be final or effectively final. I can fix it by…
0
votes
3 answers
How can you initialize a Captured variable inside a Lambda expression
In Java, it is only possible to capture final (or effectively final) variables in lambda expressions. It is possible to declare a final variable first and then initialize it once, but not if the initialization occurs in a lambda expression.
This is…

John Smith
- 47
- 4
-1
votes
1 answer
Problem in setting a variable defined in an enclosing scope
I have one map object named itemClassificationMap that gets its value from readClassificationData() method of ApachePOIExcelUtil class.
Map itemClassificationMap = new…

Priyabrat
- 21
- 4