Is it possible to create an interface extending the Serializable interface?
If yes, will that extended interface be开发者_如何学JAVAhave like the Serilizable interface? If not, why?
Yes, you can extend the Serializable
interface. If you do, all classes that implement the new subinterface will also be implementing Serializable
.
So can we do that?
Yes
will that extended interface will take the same effect as the Serilizable interface?
Yes
Yes, it's normal. I did it once when decided that all classes in my domain should be serializable. They implemented some interface already so I simply extended that interface from Serializable (as you describe).
I am explaining this by a situation often encountered in android. If you want to pass the instance of a custom listener(interface), to fragment, then the listener(interface) extend the Serializable can be a option for you. eg
Suppose there is an Interface :public interface OnDurationChangeListener extends Serializable {
public void onDurationChange(Duration duration);
}
from an Activity I want to Export the instance Listener(interface) to Fragment.
bundle.putSerializable(ARGUMENT_LISTENER, new OnDurationChangeListener() {
@Override
public void onDurationChange(Duration duration) {
// some code
}
});
And in fragment you can Get this Listener instance as:
mListener = (OnDaysSelectListener) getArguments().getSerializable(ARGUMENT_LISTENER);
And from the fragment I can Call the Callback method in activity as
mListener.onDaysSelect(mWeeKDayList);
精彩评论