`
d02540315
  • 浏览: 32545 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
社区版块
存档分类
最新评论

Marker Interface

    博客分类:
  • JDK
阅读更多
Marker interface having no methods right.. then what is the use of marker interface? for what purpose we use marker interface?

One of the "clean" features of the Java programming language is that it mandates a separation between interfaces (pure behavior) and classes (state and behavior). Interfaces are used in Java to specify the behavior of derived classes.
Often you will come across interfaces in Java that have no behavior. In other words, they are just empty interface definitions. These are known as marker interfaces. Some examples of marker interfaces in the Java API include:


- java,lang.Cloneable
- java,io.Serializable
- java.util.EventListener

Marker interfaces are also called "tag" interfaces since they tag all the derived classes into a category based on their purpose. For example, all classes that implement the Cloneable interface can be cloned (i.e., the clone() method can be called on them). The Java compiler checks to make sure that if the clone() method is called on a class and the class implements the Cloneable interface. For example, consider the following call to the clone() method on an object o:

SomeObject o = new SomeObject();
SomeObject ref = (SomeObject)(o.clone());

If the class SomeObject does not implement the interface Cloneable (and Cloneable is not implemented by any of the superclasses that SomeObject inherits from), the compiler will mark this line as an error. This is because the clone() method may only be called by objects of type "Cloneable." Hence, even though Cloneable is an empty interface, it serves an important purpose.
分享到:
评论

相关推荐

    2022年Java语言的接口与类型安全Java教程.docx

    标识接口(Marker Interface)如`Serializable`,没有任何方法,仅仅表示实现该接口的类具有特定的性质。常量接口(Constant Interface)虽然可以用来存储常量,但不推荐这样做,因为这违反了接口的设计原则,更好的...

    java 术语 a-z

    22. **标记接口 (marker interface)**:没有方法的接口,仅作为标记,表明实现它的类具有某种特性。 这些术语构成了Java编程的基础,理解并熟练应用它们对于成为专业的Java开发者至关重要。在实际编程中,掌握这些...

    MyBatis-MapperScannerConfigurer配合

    值得注意的是,MapperScannerConfigurer还支持一些其他的属性,如`annotationClass`用于指定标记Mapper接口的自定义注解,`markerInterface`则可以设置一个标记接口,只有同时实现了该接口的类才会被扫描。...

    Pattens In Java.pdf

    #### 1.4 标记接口(Marker Interface) **使用:** 标记接口是一种特殊的接口类型,它没有任何方法声明。它主要用于表示某种特性或分类。 **结构:** - **标记接口**:仅声明接口,不包含任何方法。 - **实现类**...

    Android代码-StickyHeaders

    StickyHeaders Easily add Sticky Headers to your RecyclerView Setup Implement StickyHeaderHandler in your...For items in your dataset that you want to act as sticky headers, implement the marker interface

    详解Java的MyBatis框架与Spring框架整合中的映射器注入

    `MapperScannerConfigurer`还支持通过`annotationClass`和`markerInterface`属性过滤接口,以限制哪些接口能被作为映射器。 最后,映射器的Bean名称通常是根据接口的非大写非全限定类名自动产生的。如果接口上有...

    标记

    3. **标记接口(Marker Interface)**:这种类型的接口没有声明任何方法,仅仅作为一个标记,表明实现了该接口的类具有某种特性。例如,`java.io.Serializable`接口就是一种标记接口,表示对象可以被序列化。 4. **...

    java @interface 注解详解及实例

    没有元素或者方法的注解被称为“标记(marker)”类型,例如: ```java public @interface Coder {} ``` 标记注解在使用的时候,其后面的括号可以省略。如果注释中仅包含一个元素,这个元素的名字应该为 value,...

    (EN) NGOD 2.0 - Edge Resource____ Interface - R6

    例如,ECR #21-410112005添加了对ln Band Marker扩展头的引用,而ECR #37-410112005则更新了消息流程图并清理了文本描述,以更准确地反映实际的消息类型。这些ECR的实施,反映了NGOD 2.0在不断演进和完善的过程中对...

    ccna实验之ppp 用的是繁荣模拟器

    *Mar 1 00:02:38.923: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1/2, changed state to up r1(config-if)#end r1#sh run Building configuration... *Mar 1 00:02:58.663: %SYS-5-CONFIG_I: ...

    Hp_AMap.zip

    API(Application Programming Interface)是一组预定义的函数,允许开发者访问地图服务,如绘制地图、添加标记、获取地理位置信息等。在高德地图API中,大头针通常被称为“Marker”,它用于表示地图上的特定位置。 ...

    高德地图api多地点自定义显示名字+文字标识

    API(Application Programming Interface)是应用程序接口,它允许开发者通过调用特定的函数或方法来与地图服务进行交互。高德地图API提供了JavaScript SDK和Android/iOS SDK等多种版本,适用于网页和移动设备的应用...

    ArcObject 10.3.1 For .Net 对象模型(ODM)

    此外,类图还区分了出站接口(Outbound Interface)和入站接口(Inbound Interface),这有助于理解类如何与其他类进行通信。出站接口是类对外提供的服务,而入站接口是类接受的服务。 总之,ArcObject 10.3.1 For ...

    百度地图API使用整合(javascript)

    首先,我们需要理解什么是API(Application Programming Interface),它是一组预定义的函数、类和协议,允许开发者访问特定服务或平台的功能。百度地图API是百度提供的一种服务,允许开发者在其网站上嵌入地图、...

    手机访问虚拟机

    interface FastEthernet0/0 no ip address shutdown duplex half ! interface FastEthernet1/0 ip address 192.168.1.3 255.255.255.0 duplex auto speed auto ! interface FastEthernet1/1 no ip address shutdown ...

    百度地图坐标地理位置详情显示js代码实例

    百度地图API(Application Programming Interface)是一套用于开发基于地图的应用程序的工具集。它允许开发者通过JavaScript调用各种地图服务,如绘制地图、获取地理编码、定位、路径规划等。在使用百度地图API之前...

    cisco路由器常用配置

    6. **boot-start-marker** 和 **boot-end-marker**: - 这两个命令用于标记启动配置文件的开始和结束位置,便于查找和管理配置文件。 7. **no aa new-model**: - 关闭新的AAA(认证、授权、记账)模型。 8. **...

Global site tag (gtag.js) - Google Analytics