• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Use of marker interface

 
Ranch Hand
Posts: 163
1
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi When the Serializable interface doesnot have any abstract methods, whats the use in implementing ?
 
Marshal
Posts: 79177
377
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would allow the implementation of the writeObject, writeResolve, readObject and readResolve methods to test for serialisability using something like if (!obj instanceof Serializable) ...

[edit]I am leaving it as an exercise for the reader to find the error in my post.
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It enables Java's magic serialization mechanism. Java has a default way of serializing objects without you having to override any methods. If you want to write custom serialization code, you can implement Externalizable.

Even better is to pretend these classes don't exist, and use something like JAXB instead, unless you have a lot of binary data to serialize.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 2 Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maker interfaces are no longer that useful since the introduction of Annotations in Java. The maker interfaces like Serializable and Cloneable serve special purpose from advent of Java. But for any new API you are better off creating an annotation instead.
 
Swapna latha
Ranch Hand
Posts: 163
1
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent answer Stephan. Thank you very much.

Stephan van Hulst wrote:It enables Java's magic serialization mechanism. Java has a default way of serializing objects without you having to override any methods. If you want to write custom serialization code, you can implement Externalizable.

Even better is to pretend these classes don't exist, and use something like JAXB instead, unless you have a lot of binary data to serialize.

 
reply
    Bookmark Topic Watch Topic
  • New Topic