title: Java - Converting from string to generic type
body: <p>In C# I could do something like this</p>
  
  <pre><code>public static TConvertible ChangeType&lt;TConvertible&gt;(object value) where TConvertible : IConvertible
      {
          try
          {
              if (value == null)
                  return default(TConvertible);
  
              return (TConvertible)Convert.ChangeType(value, typeof(TConvertible));
          }
          catch (System.FormatException)
          {
              return default(TConvertible);
          }
      }
  </code></pre>
  
  <p>Is there a way to do something similar in java?  I am using the android <code>SharedPreferences</code> and trying to wrap a management class around it.  Rather than using <code>getString</code>, <code>getInt</code>, <code>getLong</code>, etc, I'd like to pass in the value, store it as a string, and then convert it back on it's way out.</p>