Marker Interfaces

前端 未结 6 1827
萌比男神i
萌比男神i 2021-01-18 08:42

Could somebody pls explain the contract of marker interfaces in java?

For Ex: If Clonable is a Marker Interface with no fields/methods, then where is t

6条回答
  •  旧巷少年郎
    2021-01-18 09:08

    Clonable does not contain clone() method, which is protected in java.lang.Object.

    More info available here

    Citation From Josh Bloch's Effective Java:

    "The Cloneable interface was intended as a mixin interface for objects to advertise that they permit cloning. Unfortunately it fails to serve this purpose ... This is a highly atypical use of interfaces and not one to be emulated ... In order for implementing the interface to have any effect on a class, it and all of its superclasses must obey a fairly complex, unenforceable and largely undocumented protocol"

提交回复
热议问题