If a Marker Interface does not have any methods, how does it work?

后端 未结 5 1943
长情又很酷
长情又很酷 2020-11-27 21:08

I am aware of what marker interface is and when we need to use it. One question is still not clear to me. If a marker interface does not have any method or body, how does

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 21:35

    The only useful thing you can do with it is

    if (instance instanceof MyMarkerInterface) {
       ...
    }
    

提交回复
热议问题