开发喵星球

io03

深拷贝

分别使用JSON和序列化反序列化实现

public class Person implements Cloneable {

    private String name;
    private String no;
    private Person son;
    
    
    @Override
    public Object clone() { 
        return null;
    }
}

对象转换JSON

有一个类Game

public class Game {

    private String name;
    private double star;
    private int size;
    private double money;
}

请创建对象,并将对象转换成JSON字符串输入到文件game.txt中。

JSON转换对象

有这样一个JSON文件和一个Student类,请将它转换成Student对象,并打印出来。

{
    "id" : 1,
    "name" : "枫原万叶",
    "age" : 20,
    "password" : "123456",
    "hobby" : ["唱歌", "游戏", "学习"]
}
public class Student {

    private int id;
    private String name;
    private int age;
    private String password;
    private String[] hobby;
    
}
   
分类:Java/OOP 作者:开发喵 发表于:2023-09-15 18:43:17 阅读量:116
<<   >>


powered by kaifamiao