官方给例子 做hadoop开发的都知道
WritableComparable没有自己的方法体。
public class MyWritableComparable implements WritableComparable {
// 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 int compareTo(MyWritableComparable w) {
int thisValue = this.value;
int thatValue = ((IntWritable)o).value;
return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0 : 1));
}
}
一般序列化的类都会继承这个类型 有图为证。
看附件
http://dl2.iteye.com/upload/attachment/0096/8231/68aca470-285e-3c20-9a78-51828497e3a3.jpg
WritableComparable
猜你喜欢
转载自zhaomengsen.iteye.com/blog/2062216
今日推荐
周排行