title: Create new object vs setting its variables inside a function
body: <p>I have a <code>Rectangle</code> class and its constructor sets every variable (x, y, width, height) to a specific value. After a <code>Rectangle</code> is being created, if I want to change all of its values. To do that, is it more efficient to have a function like <code>rect.set(newX, newY, newWidth, newHeight);</code> or to call the constructor <code>r1 = new Rectangle(newX, newY, newWidth, newHeight);</code> all over again ? (Since I won't be referencing the older <code>Rectangle</code> anymore)</p>
  
  <pre><code>public Rectangle (int x, int y, int width, int height) {
      this.x = x;
      this.y = y;
      this.width = width;
      this.height = height;
  }
  
  public void set (int x, int y, int width, int height) {
      this.x = x;
      this.y = y;
      this.width = width;
      this.height = height;
  }
  </code></pre>
  
  <p>I would imagine that creating a new rectangle will create garbage, so it should be worse. Is this true ? or does java somehow optimize this ?</p>