Java: message system needs to be able to pass various objects
<p>I'm writing a messaging system to queue actions for my program to execute. I need to be able to pass various objects by the messages. I currently have a <code>Msg</code> object that accepts (<code>Action</code> enum, <code>Data&lt;?&gt;...</code>object). The <code>Data</code> object is intended to be a wrapper for any object I might pass. </p>

<p>Currently the <code>Data</code> object uses this code, with generics:</p>

<pre><code>public class Data&lt;T&gt; {

    private T data;

        public Data(T data){
        this.data = data;
    }

    public T getData(){
        return data;
    }

}
</code></pre>

<p>The <code>Msg</code> object takes <code>Data&lt;?&gt;...</code> type, so <code>Msg</code> has a <code>Data&lt;?&gt;[]</code> field.</p>

<p>If <code>getData()</code> is called on a <code>Data&lt;?&gt;</code> object, it returns the <code>Object</code> type. Obviously not ideal.</p>

<p>I need to be able to pass, say, <code>Image</code> objects as well as <code>String</code> objects. I'm certain there's a better way of passing arbitrary data.</p>