javaserializable

What is the use case or purpose of declaring field as Serializable?


class B implements Serializable {
    @Column(name = "MODIFIED_DATE")
    private Serializable modifiedDate;
}

Is there any use case or purpose to declare modifiedDate as Serializable?


Solution

  • This isn't a good example,because modifiedDate can be a Date. Think in this example:

    class Message implements Serializable {
        private String senderName;
        private int messageType;
        private Serializable payload;
        ...
    }
    

    The Message can transport many kind of thing, but if you declared payload as Object, It can fail in Runtime, because not every Object can be serialized.