mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
4958969: ObjectOutputStream example leads to non-working code
Reviewed-by: lancea, naoto
This commit is contained in:
parent
f07acfc166
commit
d0a7679d2e
3 changed files with 58 additions and 60 deletions
|
@ -66,32 +66,29 @@ import sun.reflect.misc.ReflectUtil;
|
|||
* written.
|
||||
*
|
||||
* <p>For example to write an object that can be read by the example in
|
||||
* ObjectInputStream:
|
||||
* <br>
|
||||
* <pre>
|
||||
* FileOutputStream fos = new FileOutputStream("t.tmp");
|
||||
* ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
*
|
||||
* oos.writeInt(12345);
|
||||
* oos.writeObject("Today");
|
||||
* oos.writeObject(new Date());
|
||||
*
|
||||
* oos.close();
|
||||
* </pre>
|
||||
* {@link ObjectInputStream}:
|
||||
* {@snippet lang="java":
|
||||
* try (FileOutputStream fos = new FileOutputStream("t.tmp");
|
||||
* ObjectOutputStream oos = new ObjectOutputStream(fos)) {
|
||||
* oos.writeObject("Today");
|
||||
* oos.writeObject(LocalDateTime.now());
|
||||
* } catch (Exception ex) {
|
||||
* // handle exception
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* <p>Serializable classes that require special handling during the
|
||||
* serialization and deserialization process should implement methods
|
||||
* with the following signatures:
|
||||
*
|
||||
* <br>
|
||||
* <pre>
|
||||
* private void readObject(java.io.ObjectInputStream stream)
|
||||
* throws IOException, ClassNotFoundException;
|
||||
* private void writeObject(java.io.ObjectOutputStream stream)
|
||||
* throws IOException
|
||||
* private void readObjectNoData()
|
||||
* throws ObjectStreamException;
|
||||
* </pre>
|
||||
* {@snippet lang="java":
|
||||
* private void readObject(java.io.ObjectInputStream stream)
|
||||
* throws IOException, ClassNotFoundException;
|
||||
* private void writeObject(java.io.ObjectOutputStream stream)
|
||||
* throws IOException;
|
||||
* private void readObjectNoData()
|
||||
* throws ObjectStreamException;
|
||||
* }
|
||||
*
|
||||
* <p>The method name, modifiers, return type, and number and type of
|
||||
* parameters must match exactly for the method to be used by
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue