import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
class Test implements Serializable{
private static final long serialVersionUID = 99689012974701994L;
transient int num1;
static int num2;
int num3;
transient int[] arrays={1,2,3};
transient ArrayList list=new ArrayList<>();
transient HashSet set=new HashSet<>();
transient HashMap<Integer,Integer> map=new HashMap<>();
Test(int n1,int n2,int n3){
this.num1=n1;
this.num2=n2;
this.num3=n3;
list.add(1);
set.add(2);
map.put(1,2);
}
private void get(){
System.out.println("1111");
}
}
public class Main {
public static void main(String[] args) {
//Scanner scanner = new Scanner(System.in);在线笔试
//序列化
try{
Test test=new Test(1,3);
ObjectOutputStream o=new ObjectOutputStream(new FileOutputStream("/Users/caoxiaohong/Downloads/test.txt"));
o.writeObject(test);
o.close();
}catch (Exception e){
e.printStackTrace();
}
//反序列化
try{
ObjectInputStream in=new ObjectInputStream(new FileInputStream("/Users/caoxiaohong/Downloads/test.txt"));
Test readIn=(Test)in.readObject();
System.out.println("Test.num1="+readIn.num1);
System.out.println("Test.num2="+readIn.num2);
System.out.println("Test.num3="+readIn.num3);
if(readIn.arrays==null){
System.out.println("Test.arrays is null");
}else{
System.out.println("Test.arrays.length="+readIn.arrays.length);
}
if(readIn.list==null){
System.out.println("Test.list is null");
}else{
System.out.println("Test.list.size()="+readIn.list.size());
}
if(readIn.set==null){
System.out.println("Test.set is null");
}else{
System.out.println("Test.set.size()="+readIn.set.size());
}
if(readIn.map==null){
System.out.println("Test.map is null");
}else{
System.out.println("Test.map.size()="+readIn.map.size());
}
}catch (Exception e){
e.printStackTrace();
}
}
}