所以我知道覆盖“toString”以查看你想要的东西而不是类型,但在我的情况下整体情况是:
Project1:ClassA
使用Project2:ClassB
我将Project2
包含在Project1
类路径中,编译工作正常。但是,Project2:ClassB.toString()
打印project2.package.classC
代替classB的classC元素。
注意,一旦我将classB复制到project1中,打印工作正常,我会看到元素。
以下是我在当前project1中使用的project2的classB快照:
package edu.cs;
public class FeatureWeightArrayWritable implements Writable {//classB
public int vectorSize;
public FeatureWeight[] vector; //classC = FeatureWeight
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < this.vectorSize; i++)
buffer.append(vector[i].feature + " " + vector[i].weight);
// return buffer.toString();
return "Can't see this !!! I see edu.cs.FeatureWeight@32829 ";
}
}
如果你对FeatureWeight
类有疑问,我也会覆盖它的toString,但是如果我有上面的返回消息,它甚至不应该被使用。有线索吗?
以下是我的阅读方式:
Reader reader = new SequenceFile.Reader(fs, inputPath, conf);
Writable key = (Writable) reader.getKeyClass().newInstance();
FeatureWeightArrayWritable value = new FeatureWeightArrayWritable();
while (reader.next(key, value))
System.out.println("key:" + key.toString() + ", value:" + value.toString());
答案 0 :(得分:0)
检查你的类路径,并确保你没有FeatureWeightArrayWritable
放置在某个地方的另一个副本(旧类文件,jar文件,第三个项目等)。