日期:2014-05-20 浏览次数:20757 次
public abstract class Mammal {
private String name;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
}
public class Dog extends Mammal{
public void bark(){
}
}
public class Cat extends Mammal{
public void mew(){
}
}
public class Main {
public static void main(String[] args) {
Gson gson = new Gson();
Mammal dog = new Dog();
String toGson = gson.toJson(dog);
Mammal aDog = gson.fromJson(toGson, Mammal.class);
}
}