title: Anonymous Inner Classes Inside Methods
body: <p>Please have a look at following code :</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  class Main{
       public static &lt;T&gt; List&lt;T&gt; modifiedList(final List&lt;T&gt; list){
           return new ArrayList&lt;T&gt;(){
              @Override
               public boolean add(T element){
                   super.add(element);
                   return list.add(element);
               }
           };
      }
  
       public static void main(String[] args) {
           List&lt;String&gt; originalList=new ArrayList&lt;String&gt;();
           List&lt;String&gt; duplicateList=modifiedList(originalList);
           originalList.add("1");
           originalList.add("2");
           originalList.add("3");
           System.out.println(originalList+" "+duplicateList);
           duplicateList.add("4");
           duplicateList.add("5");
           duplicateList.add("6");
           System.out.println(originalList+" "+duplicateList);
       }
  </code></pre>
  
  <p>In the above code, the instance of an anonymous inner class declared in the method modifiedList() is able to access the parameter passed to that method. AFAIK Java creates a separate bytecode file for inner classes.</p>
  
  <p>Can anyone explain how these local variable bindings are handled by Java at the bytecode level? I mean, how exactly does Java keep track of the reference to the object passed as a parameter to that method?</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p><em>[Sorry for my poor English! If you understand my question, please edit this post and remove the grammatical errors. Thanks!]</em></p>