How Marker Interface is handled by JVM

后端 未结 7 675
清歌不尽
清歌不尽 2020-12-09 23:07

Marker interface doesn\'t has any thing. It contains only interface declarations, then how it is handled by the JVM for the classes which implements this marker interface?

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 23:38

    I feel that there might be some logic behind the scenes. How else we get the CloneNotSupportedException when try calling clone() without implementing Cloneable, unless the compiler has some guidelines to check on few things when it sees the clone()!

    http://javamagic.wordpress.com/2011/12/02/marker-interface-in-java-what-why-uses-etc/

    As per this thread( Confusion in marker interface ), these are all Marker Interfaces .......... Serializable, Clonable, SingleThreadModel, EventListener, RandomAccess, Remote etc.

    If there is no logic behind the scene OR no special instructions for JVM/compiler to treat them differently, how come they behave as ONLY what is expected out of them (& JVM/compiler understands the difference between Clonable & Serializable)?

提交回复
热议问题