Pass unknown object to method in Java
<p>I'm trying to pass an instance of a class to another object, but i can't get it to work.</p>

<p>I currently have this:</p>

<pre><code>class MyClass
{
    public void myFunc()
    {
        OtherClass bla = new OtherClass(this);
    }

    public void callback()
    {
        // code...
    }
}

class OtherClass
{
    public OtherClass(Class&lt;?&gt; obj)
    {
        // do some stuff...

        // Call method from obj
        Method method = obj.getMethod("callback", SomeObject.getClass());
        method.invoke(obj, SomeObject);
    }
}
</code></pre>

<p>But now it gives me the following error:</p>

<blockquote>
  <p>The constructor OtherClass(MyClass) is undefined</p>
</blockquote>

<p>So it is expecting me to give the class name hardcode in the constructor. How can i make it a generic type, so that it accepts all classes?</p>
