I'm developing Android 2.2 application and I'm going to use Preference.OnPreferenceChangeListener interface.
I've added the following piece of code to my preference activity:
Preference somePref = findPreference(SOME_PREF);
somePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
开发者_运维技巧 public boolean onPreferenceChange(Preference preference,
Object newValue) {
// some code here
return true;
}
});
If I use 1.6 Java compiler with 1.6 source code level, then everything is perfectly fine. But if I change the level of source code to 1.5 then I've got an error message:
The method onPreferenceChange(Preference, Object) of type new Preference.OnPreferenceChangeListener(){} must override a superclass method
The question is: why?
It's because in Java 6 @Override
annotations could be applied to implementation of interface methods and methods overriding method from super class. In Java 5 at the other hand @Override
can only be applied to overriding methods.
精彩评论