它在eclipse中指出的错误是我必须删除注释覆盖。尽管我试图删除注释,但再次出现错误,它表明该方法必须重新实现
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
package com.secondarysort;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableUtils;
/**
* @author mrinmoy
*
*/
public class CompositeKey implements WritableComparable
{
public String Text;
public String count;
public CompositeKey (String Text,String count)
{
this.Text=Text;
this.count=count;
}
public CompositeKey() {
// TODO Auto-generated constructor stub
}
public String getText() {
return Text;
}
public void setText(String text) {
Text = text;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
public String toString()
{
return (new StringBuilder()).append(Text).append(',').append(count).toString();
}
@Override
public void readFields(DataInput arg0) throws IOException {
// TODO Auto-generated method stub
Text = WritableUtils.readString(arg0);
count=WritableUtils.readString(arg0);
}
@Override
public void write(DataOutput arg0) throws IOException {
// TODO Auto-generated method stub
WritableUtils.writeString(arg0,Text);
WritableUtils.writeString(arg0, count);
}
@Override
public int compareTo(CompositeKey com) {
// TODO Auto-generated method stub
int result=Text.compareTo(com.Text);
if(0==result)
{
result=count.compareTo(com.count);
}
return result;
}
}
您需要指定要重写的WritableComparable
的泛型类型,否则将无法正确重写compareTo
。这是因为编译器没有用泛型代替Object
,所以只使用CompositeKey
s的compareTo
不会覆盖它
public class CompositeKey implements WritableComparable<CompositeKey> {
// ...
}