title: Marker Interfaces in Java?
body: <p>I was being taught that Marker interface in Java is an empty interface and is used to signal to compiler or JVM that the objects of the class implementing this interface must be treated in a special way, like serializing, cloning, etc.</p>
  
  <p>But lately I have learned that it actually has nothing to do with the compiler or the JVM. For example, in case of <code>Serializable</code> interface the method <code>writeObject(Object)</code> of <code>ObjectOutputStream</code> does something like <code>instanceOf Serializable</code> to detect whether the class implements <code>Serializable</code> &amp; throws <code>NotSerializableException</code> accordingly.
  Everything is handled in the code and this seems to be a design-pattern so I think we can define our own marker interfaces.</p>
  
  <p>Now my doubts:</p>
  
  <ol>
  <li><p>Is the definition of a marker interface mentioned above in 1st point wrong? How can we define a Marker interface then?</p></li>
  <li><p>And instead of using the <code>instanceOf</code> operator why can't the method be something like <code>writeObject(Serializable)</code> so that there is a compile-time type checking rather than runtime?</p></li>
  <li><p>How are Annotations better than Marker Interfaces?</p></li>
  </ol>