Why is the Serializable interface empty in JDK source code?



  • I know what serialization is and what use it is. I also know when I don't use it. I've read item 74 of Effetive Java. My question is, what is the purpose of an empty interface, in which there is nothing to be implemented?

    package java.io;
    public interface Serializable {
    }
    

    Would it just be like a sort of markup? If so, at what time would the "marked" classes as serializable be used? And what would be the name of this marking strategy?



  • I wouldn't know why they chose to do this, maybe they don't know and question the decision, but their assumption is the most obvious explanation. She has a name, her name https://pt.stackoverflow.com/q/76511/101 and it serves only to inform that certain classes can do something, but the implementation of this is not in class. It's almost always a mistake has a better choice.

    Particularly I prefer a custom attribute annotation, something like @Serializable. any code or external tool can "look" to the class and know that it can or won't do something, just use creativity. And precisely because it shows that it has a capacity and not having the capacity inside it should not be an interface.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2