Java: Accessing a interface function from a class which implements the interface
<p><strong>Background:</strong></p>

<p>I have a list of classes (<strong>comm</strong> objects), which may or may not increase. They all implement the same method in an interface Comms:</p>

<pre><code>public int send(Socket socket, byte[] message);
</code></pre>

<p>I get a list of these <strong>comm</strong> classes by specifying the package name in the method's packageName parameter (excluding the package name itself internally in the function and doing some filtering to get just the names package comm):</p>

<pre><code>public static Class[] getClasses(String packageName); (modified it a bit from the link below)
</code></pre>

<p><a href="http://www.dzone.com/snippets/get-all-classes-within-package" rel="nofollow">http://www.dzone.com/snippets/get-all-classes-within-package</a></p>

<p>Then I have several plugins which are configurable to use one of the comm objects as base communication. </p>

<p>Comm objects:</p>

<hr>

<p>serial</p>

<p>client</p>

<p>server</p>

<p>etc.</p>

<hr>

<p>Plugins:</p>

<hr>

<p>plugin1</p>

<p>plugin2</p>

<p>etc.</p>

<hr>

<p>The manager class will receive a request for sending a control packet from a plugin, and the manager will just queue the requests and call the send function for each request on a </p>

<p><strong>Question:</strong></p>

<p>How do I access the method <code>send(Socket socket, byte[] message);</code> within manager or the plugin itself?
This involves creating a generic class object which may call send, which is cast from one of the comm classes, depending on the plugin configuration, from the string name of the comm object.</p>

<p>The configuration of which comm class is used for each plugin is stored within a database. Converting from string to a Class object works well. I just need to find a way to call the send function which resides in the interface Comm which is implemented by all the comm classes. This has to be generic. More comm classes may be added.</p>
