I have some questions:
1) What do you expect from the method public void set(String key, T value) if I invoke with this argument set("someKey", new Object()), yes then nothing happens, but it is the wrong approach.
If I create this method, I would throw an IllegalArgumentException("This " + value + " doesn't exist, please specify it.") in the last else statement.
2)The same question to the method public T get(String key, T defaultValue). And in this method would be better instead of return null, there should be throw IllegalStateException("The "+ defaultValue + " with key " + key + " doesn't exist"
First of all you are absolutely right :)
The reason that I haven't included the Exception handling was to transfer the idea of using the generic in shared preferences not the whole implementation but thanks to your comment I have included the Exception handling as well and now it looks like much more complete :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I have some questions:
1) What do you expect from the method
public void set(String key, T value)
if I invoke with this argumentset("someKey", new Object())
, yes then nothing happens, but it is the wrong approach.If I create this method, I would throw an
IllegalArgumentException("This " + value + " doesn't exist, please specify it.")
in the lastelse
statement.2)The same question to the method
public T get(String key, T defaultValue)
. And in this method would be better instead ofreturn null
, there should bethrow IllegalStateException("The "+ defaultValue + " with key " + key + " doesn't exist"
First of all you are absolutely right :)
The reason that I haven't included the Exception handling was to transfer the idea of using the generic in shared preferences not the whole implementation but thanks to your comment I have included the Exception handling as well and now it looks like much more complete :)