什么是Java中使用的标志接口? [英] What is the use of marker interfaces in Java?

查看:440
本文介绍了什么是Java中使用的标志接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当没有什么像序列化的标记接口来实现。 。有什么用实施呢?

When there is nothing to implement in the marker interfaces like Serializable . . what is the use of implementing it?

推荐答案

在早期版本的Java,标记接口是的只有这样,才能申报有关类的元数据。例如,序列化的标记接口,让类的作者说,他们的课程将正确的行为时,序列化和反序列化。

In earlier versions of Java, Marker Interfaces were the only way to declare metadata about a class. For example, the Serializable Marker Interface lets the author of a class say that their class will behave correctly when serialized and deserialized.

在现代的Java,标记接口都没有的地方。他们可以通过注解,这允许非常灵活的可完全取代元数据功能。如果您对一个类的信息,而这些信息不会改变,那么注解是重新present这是一个非常有用的方式。

In modern Java, marker interfaces have no place. They can be completely replaced by Annotations, which allow for a very flexible metadata capability. If you have information about a class, and that information never changes, then annotations are a very useful way to represent it.

这篇关于什么是Java中使用的标志接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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