title: Check type of object in generic function android java
body: <p>I have a function in my android application:</p>
  
  <pre><code>public static &lt;T&gt; void saveLocalData(Context context, String key, Class&lt;T&gt; value) {
      // Check type of value here
      SharedPreferences prefs = context.getSharedPreferences(
              Constants.PREFERENCES_KEY, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = prefs.edit();
      if(value.isAssignableFrom(String.class)){
          //Put value here
      }
      else if(value.isAssignableFrom(Boolean.class)){
          //Put value here            
      }
  
      editor.commit();
  }
  </code></pre>
  
  <p>I want to check type of value in this function (I want to check two type <code>Boolean</code> and <code>String</code>), but I don't know how to do it! Can anyone give any suggestion? Thanks!</p>
  
  <p><b>Edited:</b> Thanks every for help! I have one more problem that is how to save it value to <code>Preferences</code>? </p>