title: Java returning references by value (or by reference)
body: <p>Consider this code:</p>
  
  <pre><code>package Prova;
  
  import java.util.ArrayList;
  
  public class Prova
  {
      private ArrayList&lt;String&gt; people;
      public Prova() {
          people=new ArrayList&lt;String&gt; ();
      }
  
      public ArrayList&lt;String&gt; getPeople (){
          return people;
      }
  
      public static void main(String[] args) {
          Prova p=new Prova();
          p.go();
      }
  
      public void go(){
          ArrayList&lt;String&gt; temp=getPeople();
          temp.add("jack");
          System.out.print(getPeople());
      }
  }
  </code></pre>
  
  <p>It prints "jack".  </p>
  
  <p>Why? Doesn't this violate encapsulation? How to return it by value?</p>