(String[] args)
| 39 | |
| 40 | public class Blips { |
| 41 | public static void main(String[] args) { |
| 42 | System.out.println("Constructing objects:"); |
| 43 | Blip1 b1 = new Blip1(); |
| 44 | Blip2 b2 = new Blip2(); |
| 45 | try( |
| 46 | ObjectOutputStream o = new ObjectOutputStream( |
| 47 | new FileOutputStream("Blips.serialized")) |
| 48 | ) { |
| 49 | System.out.println("Saving objects:"); |
| 50 | o.writeObject(b1); |
| 51 | o.writeObject(b2); |
| 52 | } catch(IOException e) { |
| 53 | throw new RuntimeException(e); |
| 54 | } |
| 55 | // Now get them back: |
| 56 | System.out.println("Recovering b1:"); |
| 57 | try( |
| 58 | ObjectInputStream in = new ObjectInputStream( |
| 59 | new FileInputStream("Blips.serialized")) |
| 60 | ) { |
| 61 | b1 = (Blip1)in.readObject(); |
| 62 | } catch(IOException | ClassNotFoundException e) { |
| 63 | throw new RuntimeException(e); |
| 64 | } |
| 65 | // OOPS! Throws an exception: |
| 66 | //- System.out.println("Recovering b2:"); |
| 67 | //- b2 = (Blip2)in.readObject(); |
| 68 | } |
| 69 | } |
| 70 | /* Output: |
| 71 | Constructing objects: |
nothing calls this directly
no test coverage detected