Can you instantiate an Interface in Java? I know the quick answer is "no". But there is something I am not understanding well.
What is happening here?
SharedPreferences is a public Interface. However we do not use this interface as I have read about in the books, we do not create a class and implement SharedPreferences. Instead we use this API like this:
SharedPreferences pref = Context.getSharedPreferences("some value", 0);
So what is really happening in this code?
I think its like getSharedPreferences() is creating a SharedPreferences
object which we can then use and manipulate.
But SharedPreferences
is an Interface ... and I was told you have to implement Interfaces not create object of them. What is this in Java??
When I look at a Java API and I see a class as defined as Public Interface. How do I know when to implement that interface or when to create this type of object from it?