title: Java final modifier
body: <p>I was told that, I misunderstand effects of <code>final</code>. What are the effects of <code>final</code> keyword?</p>
  
  <p>Here is short overview of what I think, I know:</p>
  
  <blockquote>
    <h3>Java final modifier (aka aggregation relation)</h3>
    
    <p><strong>primitive variables</strong>: can be set only once. (memory and performance
    gain)<br>
    <strong>objects variables</strong>: may be modified, final applies to object
    reference.<br>
    <strong>fields</strong>: can be set only once.<br>
    <strong>methods</strong>: can't be overridden, hidden.<br>
    <strong>classes</strong>: can't be extended.<br>
    <strong>garbage collection</strong>: will force Java generational garbage collection
    mark-sweep to double sweep.</p>
  </blockquote>
  
  <h3>Can's and Cant's</h3>
  
  <ul>
  <li>Can make clone fail (this is both good and bad)</li>
  <li>Can make immutable primitives aka const</li>
  <li>Can make blank immutable - initialized at creation aka readonly</li>
  <li>Can make objects shallowly immutable </li>
  <li>Can make scope / visibility immutable</li>
  <li>Can make method invocation overhead smaller (because it does not need virtual table)</li>
  <li>Can make method arguments used as final (even if thy are not)</li>
  <li>Can make objects threadsafe (if object is defined as final, it wont make method arguments final)</li>
  <li>Can make mock tests (not that you could do anything about it - you can say bugs are intended)</li>
  <li>Can't make friends (mutable with other friends and immutable for rest)</li>
  <li>Can't make mutable that is changed to be immutable later (but can with factory pattern like fix)</li>
  <li>Can't make array elements immutable aka deeply immutable</li>
  <li>Can't make new instances of object (this is both good and bad)</li>
  <li>Can't make serialization work</li>
  </ul>
  
  <p>There are no alternatives to <code>final</code>, but there is wrapper + private and enums.</p>