title: Create new instance of object's class
body: <p>Let's say I have an object called myCar that is an instance of Car.</p>
  
  <pre><code>myCar = new Car();
  </code></pre>
  
  <p>How would I do to create a new instance of that class based on the object? Let's say that I don't know which class myCar was created from.</p>
  
  <pre><code>otherObject = new myCar.getClass()(); // Just do demonstrate what I mean (I know this doesn't work)
  </code></pre>
  
  <p>UPDATE</p>
  
  <pre><code>public class MyClass {
      public MyClass(int x, int y, Team team) { }
      public MyClass() { }
  }
  
  Object arg = new Object[] {2, 2, Game.team[0]};
  
  try {
      Constructor ctor = assignedObject.getClass().getDeclaredConstructor(int.class, int.class, Team.class);
      ctor.setAccessible(true);
      GameObject obj = (GameObject) ctor.newInstance(arg);
  
  } catch (InstantiationException x) {
      x.printStackTrace();
  } catch (IllegalAccessException x) {
      x.printStackTrace();
  } catch (InvocationTargetException x) {
      x.printStackTrace();
  } catch (NoSuchMethodException x) {
      x.printStackTrace();
  }
  </code></pre>
  
  <p>I get the following error: </p>
  
  <pre><code>java.lang.IllegalArgumentException: wrong number of arguments
  </code></pre>
  
  <p>getDeclaredConstructor() works and finds my constructor with three args, but newInstance(arg) won't work for some reason, it says "wrong number of arguments". Any idea why?</p>