Java how to optional override method in abstract class?

前端 未结 5 1111
小鲜肉
小鲜肉 2021-02-07 01:50

Let\'s say we have a base class:

public abstract class BaseFragment extends Fragment {
    ...
    protected abstract boolean postExec();
    ...
}
5条回答
  •  日久生厌
    2021-02-07 02:31

    Abstract methods purpose is to force you to implement them.

    If add an abstract method in your superclass, you have to refactor your code and provide implementation; your program will be inconsistent even with default implementations - what if you need to return a custom type? I'd take my time to provide proper implementation, as I will probably need to call such methods if I added them.

提交回复
热议问题