• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Use of marker interface

 
Ranch Hand
Posts: 157
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi When the Serializable interface doesnot have any abstract methods, whats the use in implementing ?
 
Marshal
Posts: 67443
257
  • Likes 3
  • Mark post as helpful
  • send pies
  • 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: 11185
244
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 2 Likes 1
  • Mark post as helpful
  • send pies
  • 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: 157
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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.

 
I was her plaything! And so was this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!