How to call method of a unknown object
<p>I want to do something different with java reflection. The program i written to add global listeners to java components when applets are opened from browser. An event fired and i get event source object. Here i don't know the actual class name that object referring to. </p>

<pre><code>if(object.getClass.getName().contains("oracle.ewt.laf.basic.BasicTabBarUI$Menu"))
{
   // here we can invoke methods,fields,etc using reflection
}
</code></pre>

<p>I can call the methods of BasicTabBarUI$Menu class with reflection. </p>

<p>Suppose now i have the following lines with me in the above if block</p>

<pre><code>LWMenuItem menuItem = (LWMenuItem)object;
menuItem.getLabel());
</code></pre>

<p>I don't want to specify LWMenuItem class name , instead i want to call its method getLabel(). If we know the class name , we can do as above. But how can we do same with reflection. How can we do casting in reflection?</p>