1

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

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

4

1 回答 1

1

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

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

例如:

在其他地方Runtime实现像

if (SomeObjImpMarkerInterface instanceof SomeMarkerInterface ) {
        // Hey this object is that type
    } else {
        // Not that type.
    }
于 2014-07-15T13:05:16.910 回答