Linked Questions

36 votes
8 answers
32k views

I was wondering is there any usability of using final local variables. Variables are not overridden anyway when inheritance comes into picture. For example a simple code as below public static void ...
Aniket Thakur's user avatar
32 votes
5 answers
37k views

Possible Duplicate: Why would one mark local variables and method parameters as “final” in Java? I was checking some Java code, I am not good at java at least have some knowledge what ...
Tarik's user avatar
  • 82.2k
6 votes
3 answers
18k views

Possible Duplicate: Is there any performance reason to declare method parameters final in Java? Why would one mark local variables and method parameters as “final” in Java? I am ...
user avatar
0 votes
2 answers
261 views

Possible Duplicate: Why would one mark local variables and method parameters as “final” in Java? I used PMD in my code and it always tells me to make method local variables final. Can ...
Madz's user avatar
  • 1,279
1 vote
0 answers
39 views

What is the point of declaring instance variable as final final List<Integer> intList = new ArrayList<Integer>();
greenHorn's user avatar
  • 567
7743 votes
87 answers
2.8m views

I always thought Java uses pass-by-reference. However, I read a blog post which claims that Java uses pass-by-value. I don't think I understand the distinction the author is making. What is the ...
211 votes
25 answers
76k views

In Java, there is a practice of declaring every variable (local or class), parameter final if they really are. Though this makes the code a lot more verbose, this helps in easy reading/grasping of ...
surajs's user avatar
  • 2,370
210 votes
15 answers
83k views

I've found a couple of references (for example) that suggest using final as much as possible and I'm wondering how important that is. This is mainly in the the context of method parameters and local ...
eaolson's user avatar
  • 15.2k
122 votes
4 answers
30k views

Is there any performance reason to declare method parameters final in Java? As in: public void foo(int bar) { ... } Versus: public void foo(final int bar) { ... } Assuming that bar is only read and ...
Kip's user avatar
  • 110k
33 votes
7 answers
4k views

I come from a C++ background and I am currently learning Java. One question arose when I have tried using some third party libraries. How do I determine if the call to a method taking an object ...
ItalianMonkey's user avatar
30 votes
5 answers
21k views

Compare this method: void doStuff(String val) { if (val == null) { val = DEFAULT_VALUE; } // lots of complex processing on val } ... to this method: void doStuff(String origVal) ...
Matt McHenry's user avatar
  • 21.2k
27 votes
5 answers
17k views

I understand how the below statement works. for(final Animal animal : animalList){ //do some function } But what is the purpose of using the final keyword here ?
Krithika Vittal's user avatar
12 votes
6 answers
4k views

What is faster in Java. Accessing an array index directly multiple times, or saving the value of the array index to a new variable and use this for following compution? acces index if ((shape....
Andreas Linden's user avatar
6 votes
5 answers
1k views

If I look at the java source source code in the OpenJDK or Hibernate or Apache I have yet to see any local variables declared final. This suggests that the developers of some of the most widely used ...
user695654's user avatar
3 votes
3 answers
4k views

Stream<Map.Entry<String, List<Object>>> sorted = index.entrySet().stream() .sorted(Map.Entry.comparingByValue()); The method sorted(Comparator<? super Map.Entry&...
Pete's user avatar
  • 514

15 30 50 per page