title: Java Pass-by-reference not working?
body: <p>I'm trying to make this little game in Java but I seem to have stumbled upon a variable reference problem.
  My Entity class, which Player extends from, keeps a variable of type Dimension.
  This Dimension gets set via the constructor of the Entity class like so:</p>
  
  <pre><code>protected Dimension dimension;
  
  public Entity(Dimension dimension) {
      this.dimension = dimension;
  }
  </code></pre>
  
  <p>In my player class, this is how I pass the dimension object via his constructur:</p>
  
  <pre><code>public Player(Dimension dimension) {
      super(dimension);
  }
  </code></pre>
  
  <p>I also have a Game class, which keeps all the possible dimensions, plus an extra variable called activedimension which keeps a reference to the active game dimension.</p>
  
  <pre><code>private Dimension activedimension;
  private Dimension overworld;
  private Dimension otherdimension;
  
  public Game() {
      overworld = new OverWorldDimension();
      otherdimension = new OtherDimension();
      activedimension = overworld;
  }
  </code></pre>
  
  <p>When I want my overworld dimension to reset, I use this method:</p>
  
  <pre><code>public void resetOverWorld() {
      overworld = new OverWorldDimension();
      activedimension = overworld;
  }
  </code></pre>
  
  <p>Now, whenever I call this resetOverWorld method from anywhere, it seems like my activedimension really did refresh, but the dimension stored in my Player/Enitity class didn't.
  I'm fairly new to Java, so I don't know if I'm doing something wrong with the variable-references being passed through constructors and methods.
  My application seems to copy a dimension object somewhere instead of passing the reference, but I can't figure out where.</p>
  
  <p>Any help or thoughts are welcome.
  Thanks in advance
  ~Krikke</p>