【问题标题】:What is the use of marker interface in java when we have no methods in it and how it gets into action? [duplicate]当我们没有方法时,标记接口在java中的用途是什么以及它是如何起作用的? [复制]
【发布时间】:2014-09-05 16:31:41
【问题描述】:

我对 java 中的标记接口感到困惑。

当我们在标记接口中没有方法时,谁能告诉我,然后从哪里调用它。我们是否也必须明确地实现这一点。

【问题讨论】:

    标签: java marker-interfaces


    【解决方案1】:

    它就像任何其他界面一样。

    并用于在运行时对对象进行类型检查。

    例如:

    在其他地方Runtime 实现了像

    这样的对象
    if (SomeObjImpMarkerInterface instanceof SomeMarkerInterface ) {
            // Hey this object is that type
        } else {
            // Not that type.
        }
    

    【讨论】:

      猜你喜欢
      • 2010-12-31
      • 2022-01-31
      • 1970-01-01
      • 2012-12-24
      • 2011-05-25
      • 2012-12-11
      • 2014-10-25
      • 2020-09-27
      • 1970-01-01
      相关资源
      最近更新 更多