Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.vk.vitalypavlenko.newSandbox;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- public class MethodInnerClassTest implements Serializable {
- static Serializable someReference;
- public void Method(String z) {
- final String y = z;
- class Inner implements Serializable {
- int x;
- Inner(int x) {
- this.x = x;
- }
- public String toString() {
- return "hi, i'm Inner, my x is " + x +
- " and y in my method is " + y;
- }
- }
- if (someReference == null) {
- someReference = new Inner(42);
- } else {
- System.out.println((Inner) someReference);
- System.out.println("But actually y is " + y);
- }
- }
- public static void main(String[] args) throws IOException {
- MethodInnerClassTest mict = new MethodInnerClassTest();
- ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("inner.ser"));
- mict.Method("aaaaaa");
- oos.writeObject(someReference);
- mict.Method("bbbbbb");
- oos.writeObject(someReference);
- someReference = null;
- mict.Method("cccccc");
- oos.writeObject(someReference);
- mict.Method("dddddd");
- oos.writeObject(someReference);
- oos.close();
- }
- }
Add Comment
Please, Sign In to add comment