Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharedPreferences : Is it a class or an interface?

I'm confused, please help me.

Android developers documentation say SharedPreferences is an Interface and also we can see on grepCode that the SharedPreferences is an Interface.

But developers.android also says SharedPreferences is a Class.

They write.

"The SharedPreferences class provides a general framework ..."

So, SharedPreferences is a Class or an Interface?

like image 850
Stanly T Avatar asked Feb 07 '23 18:02

Stanly T


1 Answers

The documentations is not wrong, but may be it is a bit confusing.

If you see the code, you'll see that SharedPreferences is actually an interface. But as you mentioned, here it is referring to its implementation as class which is actually SharedPreferencesImpl and you can look into its implementation here. When you make a call to getSharedPreferences() method, it actually returns the object of SharedPreferencesImpl which is a class that implements SharedPreferences interface.

like image 121
Rehan Avatar answered Feb 09 '23 08:02

Rehan