数据类型
自定义类型
实现WritableComparable 或者Writable接口
然后实现接口的方法:
public class UserTestWriteable implements WritableComparable<UserTestWriteable> {
//定义成员变量
private String firstKey;
private int secondKey;
@Override
public int compareTo(UserTestWriteable o) {
int comp = this.getFirstKey().compareTo( o.getFirstKey() );
if(comp ==0){
return Integer.valueOf( this.secondKey ).compareTo( Integer.valueOf( o.secondKey ) );
}
return comp;
}
//序列化
@Override
public void write(DataOutput out) throws IOException {
out.writeUTF(firstKey);
out.writeInt(secondKey);
}
//反序列化
@Override
public void readFields(DataInput in) throws IOException {
this.firstKey = in.readUTF();
this.secondKey = in.readInt();
}
...省略get/set方法
//自定义tostring格式
@Override
public String toString() {
return firstKey + "--" + secondKey;
}
}