I have found this in an article. It implements Parcelable for passing data between activities in Android
public class Student implements Parcelable {
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Student createFromParcel(Parcel in) {
return new Student(in);
}
public Student[] newArray(int size) {
return new Student[size];
}
};
private long id;
private String name;
private String grade;
// Constructor
public Student(long id, String name, String grade){
this.id = id;
this.name = name;
this.grade = grade;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
// Parcelling part
public Student(Parcel in){
this.id = in.readLong();
this.name = in.readString();
this.grade = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.id);
dest.writeString(this.name);
dest.writeString(this.grade);
}
@Override
public String toString() {
return "Student{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", grade='" + grade + '\'' +
'}';
}
}
In this example, a field CREATOR is declared and implements Parcelable.Creator Interface.This is an anonymous class.Does this mean anonymous classes can also be created as members of a class? and I have learnt from other sources that Anonymous classes cannot be static, but here it is declared as static. I don't understand the context of anonymous class in this example.Can someone explain this?