Is it possible to have a map that only allows value types based on the key?
<p>I know this sounds a little crazy but here it is. I have an enum type that represents represents a bunch of different properties. Each could be just a string but it would be nice to enforce some kind of type safety. So basically check the type associated with each enum value and throw an exception if there is a mismatch. I guess it could be done with instance of but I am curious if there is another way to do this without instanceof. I know that may not be possible but I am curious. </p>

<p>Edit, I created a new example that I think illustrates what I am asking better:</p>

<pre><code>public class CmisProperties {

    public enum CmisPropEnum{
        Name (PropertyIds.NAME, new String() ),
        CreatedBy (PropertyIds.CREATED_BY, new String()  ),
        CreationDate (PropertyIds.CREATION_DATE, new Date() ),
        LastModifiedBy (PropertyIds.LAST_MODIFIED_BY, new String() ),
        LastModificationDate (PropertyIds.LAST_MODIFICATION_DATE, new Date() ),
        ChangeToken (PropertyIds.CHANGE_TOKEN, new String()  );

            private String propId;

        CmisPropEnum ( String propId , Object templateObject ){
            this.propId = propId;
        }

        public &lt;T&gt; String getPropId(){
            return propId;
        }
    }

        private Map&lt;CmisPropEnum, Object&gt; propertyMap = new HashMap&lt;CmisPropEnum, Object&gt;();

    public Object getProperty(CmisPropEnum propEnum){
         return propertyMap.get(propEnum.getPropId());
    }

    public void setProperty( CmisPropEnum propEnum, Object value){
             propertyMap.put(propEnum, value);
    }
}
</code></pre>

<p>Later on I want this to happen:</p>

<pre><code>CmisProperties props = new CmisProperties();
/* This causes a compile time exception */
props.setProperty(CmisPropEnum.CreationDate, "foobar" );
/* This I want to be ok, because the type matches that in the enum */
props.setProperty(CmisPropEnum.CreationDate, new Date() );
</code></pre>
