0

As Serializable and Cloneable is marker Interface (interface which is not having any method), so if we create our own marker interface then what will be the difference between these two.

Sumit Singh
  • 111
  • 1
  • 5

1 Answers1

0

Serializable and Cloneable are standard interfaces. They both belongs to "protected" packages (which means you cannot add classes to them - well you can, but it's not something you do everyday).

java.io.Serializable
java.lang.Cloneable

They're recognized by the JVM at runtime.
For example calling clone() on an object which does not implement Cloneable will throw a

java.lang.CloneNotSupportedException

You might want to use marker interfaces for custom runtime checks, or even for compile time processing. However the recommended way is to use annotations.

LppEdd
  • 20,274
  • 11
  • 84
  • 139
  • what you have written is right but if we create our custom marker interface. they will also recognise by JVM at runtime and even if we bound the program that if its containing the instance of our custom marker interface then do this work. Then what will be the difference in both.... – Sumit Singh Feb 20 '19 at 21:22
  • @SumitSingh mmh I think I'm missing your point. Could you maybe write an example of what you'd like to do? – LppEdd Feb 20 '19 at 21:30