Type casting from an Object
<p>I have some code in Java as follows:</p>

<pre><code>private Object addVertex(String label, int posX, int posY) {
 Vertex newVertex = new Vertex();
 this.getModel().beginUpdate();
 try {
  newVertex = insertVertex(parent, null, label, posX, posY, 80, 30);
 }
 finally {
  this.getModel().endUpdate();
 }
 return newVertex;
}
</code></pre>

<p>That code wont work because of a type mismatch, insertVertex will return an Object, but I get a type mismatch since it can't convert from Object to Vertex (which is an object I created).</p>

<p>Firstly, how come that can't work, since the object Vertex inherits Object by default surely you should be able to do that.</p>

<p>Also, if I try and type cast the Object to a Vertex as follows</p>

<pre><code>newVertex = (Vertex) insertVertex(parent, null, label, posX, posY, 80, 30);
</code></pre>

<p>I get an error saying I can't make that conversion.</p>
