Java DateFormat.Field readResolve() Example
DateFormat.Field class readResolve() method example. This example shows you how to use readResolve() method.
Syntax is : protected Object readResolve() throws InvalidObjectException
This method resolves instances being deserialized to the predefined constants.
Here is the code.
/**
* @(#) ReadResolveDateFormatField.java
* A class representing use of method readResolve() of DateFormat.Field
class in java.text Package.
* @Version 13-May-2008
* @author Rose India Team
*/
import java.io.InvalidObjectException;
import java.util.*;
import java.text.*;
class ReadResolveDateFormatField extends DateFormat.Field {
ReadResolveDateFormatField(String str, int value) {
super(str, value);
}
public static void main(String[] args) {
try {
//Create Date object that will be initialized to the current date.
Date date = new Date();
System.out.println("Date by Date class : " + date.toString());
// Create new object of GetCalendarFieldDateFormatField class.
ReadResolveDateFormatField obj = new
ReadResolveDateFormatField("Mahendra", Calendar.MONDAY);
// readResolve method call.
String str = obj.readResolve().toString();
System.out.print("Calendar field of object obj : " + str);
} catch (InvalidObjectException ex) {
System.out.println("Unable to implement readResolve.");
}
}
} |
Output of the program.
Date by Date class : Fri Jun 13 18:17:10 GMT+05:30 2008
Unable to implement readResolve. |
|