prefser icon indicating copy to clipboard operation
prefser copied to clipboard

Provide convenience methods on top of get() for basic types

Open semanticer opened this issue 9 years ago • 1 comments

This looks a little bit noisy in my code

Boolean value = prefser.get("key", Boolean.class, false);
Float value = prefser.get("key", Float.class, 1.0f);
Integer value = prefser.get("key", Integer.class, 1);
Long value = prefser.get("key", Long.class, 1.0l);
Double value = prefser.get("key", Double.class, 1.0);
String value = prefser.get("key", String.class, "default string");

it would be nice to have a convenience methods like

Boolean value = prefser.getBoolean("key",  false);
Float value = prefser.getFloat("key", 1.0f);
Integer value = prefser.getInt("key", 1);
Long value = prefser.getLong("key", 1.0l);
Double value = prefser.getDouble("key", 1.0);
String value = prefser.getString("key", "default string");

And still use get() for custom objects. It's also more similar to SharedPreferences approach.

semanticer avatar Dec 19 '15 17:12 semanticer

Not bad idea. I think, we can create such methods just for basic types, so people can use them if they want to. In addition, I would like to keep backward compatibility if someone wants to use only basic get(...) method. I'm just wondering, if API of the library will be consistent after adding such methods, so I'm not 100% sure about this change. How about put(...), getAndObserve(...) and observe(...) methods? Moreover, API will become bigger.

pwittchen avatar Dec 19 '15 17:12 pwittchen