title: How does the "final" keyword in Java work? (I can still modify an object.)
body: <p>In Java we use <code>final</code> keyword with variables to specify its values are not to be changed.
  But I see that you can change the value in the constructor / methods of the class. Again, if the variable is <code>static</code> then it is a compilation error.</p>
  
  <p>Here is the code: </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  class Test {
    private final List foo;
  
    public Test()
    {
        foo = new ArrayList();
        foo.add("foo"); // Modification-1
    }
    public static void main(String[] args) 
    {
        Test t = new Test();
        t.foo.add("bar"); // Modification-2
        System.out.println("print - " + t.foo);
    }
  }
  </code></pre>
  
  <p>Above code works fine and no errors.</p>
  
  <p>Now change the variable as <code>static</code>:</p>
  
  <pre><code>private static final List foo;
  </code></pre>
  
  <p>Now it is a compilation error. How does this <code>final</code> really work?</p>