如果标记接口没有任何方法,它是如何工作的? [英] If a Marker Interface does not have any methods, how does it work?

查看:123
本文介绍了如果标记接口没有任何方法,它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道什么是标记接口以及何时需要使用它。我仍然不清楚一个问题。如果标记接口没有任何方法或主体,它在运行时如何工作?

解决方案

标记接口没有这样工作。顾名思义,它只是将一个类标记为特定类型。其他一些代码必须检查标记的存在并根据该信息执行某些操作。



这些天注释通常执行与标记接口之前相同的角色。 / p>

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 it work at runtime?

解决方案

A marker interface doesn't "work" as such. As the name suggests, it just marks a class as being of a particular type. Some other code has to check for the existence of the marker and do something based on that information.

These days annotations often perform the same role that marker interfaces did previously.

这篇关于如果标记接口没有任何方法,它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆