IntWritable.set(IntWritable) 抛出错误

IntWritable.set(IntWritable) is throwing error

在编写示例代码以测试 hadoop 中的自定义数据时。我收到以下错误:

The method set(int) in the type IntWritable is not applicable for the arguments (IntWritable)

我已经检查了 IntWritable.set(int value)set 方法。 如何将 hadoop IntWritable 转换为 Int 然后返回 IntWritable#set 方法将转换回 IntWritable.

public class customText implements Writable{

private Text depName;

//default constr
private IntWritable depId;
customText(){
    this.depName = new Text();
    this.depId = new IntWritable();

}

customText(Text depName , IntWritable depId ){

    this.depName.set(depName);
    this.depId.set(depId);

我也试过this.depid=depId但是没用。

谢谢

应该是:

customText(Text depName , IntWritable depId ){
    this.depName.set(depName);
    this.depId.set(depId.get());
}

set 的方法签名是 set(int value),因此您必须 get() 来自 IntWritable 的 int。