title: Does a passed final variable in Java stay final on the other side?
body: <p>I've just come across some code that's confusing me slightly; there are really 2 variations that I'd like to clarify.</p>
  
  <p><strong>Example 1:</strong></p>
  
  <pre><code>public String getFilepath(){
          final File file = new File(this.folder, this.filename);
          return file.getAbsolutePath();
      }
  </code></pre>
  
  <p>What would be the purpose of declaring <code>file</code> "<code>final</code>"? Since Java primitives are passed by value, and <code>getAbsolutePath()</code> is just returning a <code>String</code>, the variable won't be <code>final</code> on the other side (calling method), will it? And since the <code>file</code> variable only exists within the scope of these 2 lines, I can't really see any purpose of the <code>final</code> keyword. Is there something I'm missing? Anyone see a reason to do this?</p>
  
  <p><strong>Example 2:</strong></p>
  
  <pre><code>public String getFilepath(){
          final File file = new File(this.folder, this.filename);
          return file;
      }
  </code></pre>
  
  <p>Since here the actual object is being returned... Does that mean the <code>file</code> variable will be constant/<code>final</code> on the other side...? It doesn't seem to make sense.</p>
  
  <p>In general, it seems to me that you pass a variable, <em>without</em> it's access type. As in, I can have a <code>private</code> variable in a function with a <code>public</code> get function that returns it - but the variable that receives it by calling the function has to specify an access modifier. So if it specifies <code>public</code>, the returned variable will be <code>public</code> in that scope. If it specifies <code>private</code>, the returned variable will be <code>private</code> in that scope. Is there a difference with <code>final</code>? Is the "constancy" of a variable something that can be passed? This strikes me as rather improbable, considering what I know of Java.</p>
  
  <p>Or am I missing the point entirely and there's some other purpose of the <code>final</code> keyword in the above code?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I checked back with the original developer who wrote the code, and he said he only put the <code>final</code> keyword in because he had originally thought the method would be a lot longer and wanted to ensure that the file stayed constant throughout. He also said that he generally declares variables that should not be changed as <code>final</code>, as a rule across the board and sort of on principle - a point that both the answers below mentioned. So it seems I was reading too much into a simple extra keyword included for standards reasons. Thanks everyone!</p>