简体   繁体   中英

Serialization on runtime and partial Serialization

I have a below class as example

class Employee implements Serializable{
transient String x;
String y;

Date d= new Date("5/10/1984");

}

1)Can i serialize x at run time? 2)Can i serialize only month and day not year in Date?

1) Date internally consists of a long (ms since 1.1.1970 utc). Month and day then are computed from the long and the current time zone. You can serialize a date, it will basically transmit the embedded long. 2) You can't, however you simply might serialize the strings. Beware, if this is deserialized in another locale this might create unexpected behaviour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM