爲了讓人好奇,我不確定如何爲此設置標題。我正在學習http://developer.android.com/training/basics/data-storage/shared-preferences.html,並想澄清一點點。SharedPreferences.Editor(Android)混淆
比方說,我們有:
SharedPreferences sharedPref = getSharedPreferences(USERNAME, MODE_PRIVATE);
和
SharedPreferences.Editor editor = sharedPref.edit();
當我將鼠標上編輯()(我使用Eclipse IDE),我瞭解到,
開放聲明編輯器android.content.SharedPreferences.edit()
公共抽象SharedPreferences.Editor編輯()
API等級新增1
創建這些首選項,通過它可以進行修改,在>數據的喜好和原子提交這些更改回新的編輯器SharedPreferences>對象。
請注意,您必須調用commit()以在編輯器中執行的任何更改實際顯示在SharedPreferences中。
返回 返回SharedPreferences.Editor接口的新實例,允許您修改此SharedPreferences對象中的值。
所以我其實這裏有3個小題:
1 /編輯()是一個抽象方法,所以在已編輯()被重寫什麼課(我已經瞭解到,「公共抽象SharedPreferences .Editor edit()「位於SharedPreferences接口中,所以必須有一些類實現此接口)
2/SharedPreferences.Editor是一個接口。據我所知,一個接口不能被實例化。這個編輯器對象如何能夠接收API中所述的「SharedPreferences.Editor接口的新實例」。
3 /我剛剛開始學習Android幾天,這是一種很好的方法,我以這種方式學習,這意味着解剖所有東西以使它們對我清楚嗎?
謝謝
我想我也找出了我的第二個問題的答案。它應該是這樣的:http://stackoverflow.com/questions/9157784/java-interface-with-new-keyword-how-is-that-possible。謝謝你的答案。 –