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
,因此仅采用compareTo
的CompositeKey
不会覆盖它。更改为:
public class CompositeKey implements WritableComparable<CompositeKey> {
// ...
}