Optional method in Java Interface

前端 未结 4 2056
眼角桃花
眼角桃花 2021-01-03 20:46

I have an interface with several method definitions, and I would not like to require some of them.

Is this possible? if so, how can i implement this

4条回答
  •  长发绾君心
    2021-01-03 21:29

    There is no @Optional annotation in Java. One thing you can do is to create an interface, and then create an abstract class that provides stub implementations. Your classes can then extend this base class and override the methods they are interested in.

提交回复
热议问题