about class design considerations for a code segment
With respect to the following code segment, why does the definition of
method read has a MyWritable, while other two methods write and readFields
do not have? Besides, why read should be defined as static? How to
understand this design?
public class MyWritable implements Writable {
// Some data
private int counter;
private long timestamp;
public void write(DataOutput out) throws IOException {
out.writeInt(counter);
out.writeLong(timestamp);
}
public void readFields(DataInput in) throws IOException {
counter = in.readInt();
timestamp = in.readLong();
}
public static MyWritable read(DataInput in) throws IOException {
MyWritable w = new MyWritable();
w.readFields(in);
return w;
}
}
No comments:
Post a Comment