I am using a method like this
private static <T> void setPreference(String key, T value)
{
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Controller.getContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(key, value.toString());
    editor.commit();
}
Unfortunately, putString is one of multiple put methods.  I also want to use putBoolean and putInt.  My problem is that I want to support the specific types (I don't want to save everything as a string like I am doing), and I want to reduce code duplication as much as possible.  I'm used to C# where this kind of thing is very easy, so I feel like I'm missing something obvious.
Make several overloads: one that accepts <T extends Boolean>, etc, for each of the specific types you want to carve out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With