How to get rid of "Type safety: Unchecked cast from Object to Map<String,String>"
<p>I am using below code to extract <code>deviceId</code> from Spring Authentication class.</p>

<pre><code>import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import com.google.common.base.Optional;

public static Optional&lt;String&gt; getId() {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (!auth.isAuthenticated()) {
        return Optional.absent();
    }
    // I see a warning as "Type safety: Unchecked cast from Object to Map&lt;String,String&gt;"
    Map&lt;String, String&gt; details = (Map&lt;String, String&gt;) auth.getDetails();
    return Optional.of(details.get("deviceId"));
}
</code></pre>

<p>How do I get over of this Type safety warning message? I want to avoid adding <code>Suprress Warnings</code> tag.</p>

<blockquote>
  <p>Type safety: Unchecked cast from <code>Object</code> to <code>Map&lt;String,String&gt;</code></p>
</blockquote>