Guest User

Untitled

a guest
May 15th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.24 KB | None | 0 0
  1. package com.vk.vitalypavlenko.newSandbox;
  2.  
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.ObjectOutputStream;
  6. import java.io.Serializable;
  7.  
  8.  
  9. public class MethodInnerClassTest implements Serializable {
  10.  
  11.     static Serializable someReference;
  12.    
  13.     public void Method(String z) {     
  14.         final String y = z;
  15.        
  16.         class Inner implements Serializable {          
  17.             int x;
  18.            
  19.             Inner(int x) {
  20.                 this.x = x;
  21.             }
  22.            
  23.             public String toString() {
  24.                 return "hi, i'm Inner, my x is " + x +
  25.                     " and y in my method is " + y;
  26.             }
  27.         }
  28.        
  29.         if (someReference == null) {
  30.             someReference = new Inner(42);
  31.         } else {
  32.             System.out.println((Inner) someReference);
  33.             System.out.println("But actually y is " + y);
  34.         }      
  35.     }
  36.    
  37.     public static void main(String[] args) throws IOException {
  38.         MethodInnerClassTest mict = new MethodInnerClassTest();
  39.         ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("inner.ser"));
  40.        
  41.         mict.Method("aaaaaa");
  42.         oos.writeObject(someReference);    
  43.         mict.Method("bbbbbb");
  44.         oos.writeObject(someReference);
  45.         someReference = null;
  46.         mict.Method("cccccc");
  47.         oos.writeObject(someReference);
  48.         mict.Method("dddddd");
  49.         oos.writeObject(someReference);
  50.         oos.close();
  51.     }
  52.  
  53. }
Add Comment
Please, Sign In to add comment