如何在Java中编写自己的标记接口?

编程入门 行业动态 更新时间:2024-10-26 00:28:12
本文介绍了如何在Java中编写自己的标记接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道java中的标记界面。它用于定义关于类的特定行为。例如,Serializable接口具有将对象存储到字节流及其反向过程的特定功能。但我不知道这个特定行为的实现位置,因为它没有任何方法。

I know marker interface in java. It is used to define a specific behaviour about a class. For example, Serializable interface has the specific ability to store an object into byte stream and its reverse process. But I don't know where this specific behaviour is implemented, because it doesn't have any method in it.

  • JVM如何调用此方法具体行为?
  • 如何编写我们自己的标记界面?你能给我一个简单的用户定义标记界面供我理解吗?
  • 是否可以在标记界面中使用方法?
  • 请指导我解决此问题。

    推荐答案

  • 序列化由 ObjectInputStream 和 ObjectOutputStream 类处理。如果某个类具有特殊的序列化需求,则在 API 。反射用于调用这些方法。

  • Serialization is handled by the ObjectInputStream and ObjectOutputStream classes. If a class has special serialization needs, the methods to create are outlined in the API. Reflection is used to invoke these methods.

    与编写任何其他界面的方式相同。

    The same way you would write any other interface.

    没有什么可以阻止你将方法放在标记界面中。

    There's nothing stopping you from putting methods in a marker interface.

    现在更常见的做法是使用注释提供相同的元数据标记接口。

    The more common practice now is to use annotations to provide the same metadata marker interfaces provide.

  • 更多推荐

    如何在Java中编写自己的标记接口?

    本文发布于:2023-11-22 20:15:16,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1618854.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:自己的   标记   接口   如何在   Java

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!