title: java.lang.ClassCastException: java.util.HashSet cannot be cast to Custom Class
body: <pre><code>FATAL EXCEPTION: AsyncTask #2
  Process: my.app, PID: 15441
  java.lang.ClassCastException: java.util.HashSet cannot be cast to my.app.ChatNotificationHashSet
  at my.app.UserHandler.getChatNotificationMessage(UserHandler.java:127)
  at my.app.NotificationUtil.getChatTitle(NotificationUtil.java:100)
  at my.app.NotificationUtil.showChat(NotificationUtil.java:71)
  at my.app.service.GCMListenerService.onMessageReceived(GCMListenerService.java:47)
  at com.google.android.gms.gcm.GcmListenerService.zzq(Unknown Source)
  at com.google.android.gms.gcm.GcmListenerService.zzp(Unknown Source)
  at com.google.android.gms.gcm.GcmListenerService.zzo(Unknown Source)
  at com.google.android.gms.gcm.GcmListenerService.zza(Unknown Source)
  at com.google.android.gms.gcm.GcmListenerService$1.run(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p><strong>ChatNotificationHashSet</strong></p>
  
  <pre><code>public class ChatNotificationHashSet&lt;E&gt; extends LinkedHashSet&lt;String&gt; {
  
      @Override
      public String toString() {
          // ...
      }
  }
  </code></pre>
  
  <p><strong>UserHandler (where the exception occurs)</strong></p>
  
  <pre><code>public ChatNotificationHashSet&lt;String&gt; getChatNotificationMessage() {
          return (ChatNotificationHashSet&lt;String&gt;) pref.getStringSet(CHAT_NOTIFICATION_MESSAGE, null); // &lt;- Exception occurs here
      }
  
      public void setChatNotificationMessage(ChatNotificationHashSet&lt;String&gt; messages) {
          SharedPreferences.Editor editor = pref.edit();
          editor.putStringSet(CHAT_NOTIFICATION_MESSAGE, messages);
          editor.commit();
      }
  </code></pre>
  
  <hr>
  
  <p>How can this happen? There shouldn't be any problems when casting <code>null</code> to <code>ChatNotificationHashSet&lt;String&gt;</code>, right? I couldn't think of any other problem.</p>