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

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

问题描述

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

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天全站免登陆