我有一个问题,类型 DefaultMutableTreeNode 变量的值一旦在 Spark mapToPair() 函数中使用就会变为默认值。这是我的代码:
public class CA implements Serializable{
private final JavaRDD<String> input;
private final List<IB> bList;
public boolean FuncWithSpark(){
/*
!!!at this point, bList.get(0).getD().getRoot() return a valid tree node
*/
JavaRDD<Boolean> counters = input.mapToPair(new PairFunction<String, String, List<String>>() {
@Override
public Tuple2<String, List<String>> call(String s) throws Exception {
/*
!!!at this point, bList.get(0).getD().getRoot() return an uninitialized tree node with default values
*/
...
}
}
}
public CA(JavaRDD<String> input, List<IB> bList) {
this.input = input;
this.bList = bList;
}
}
接口 IB、ID、CB 和 CD 类定义如下:
public interface IB {
...
}
public interface ID {
...
}
public class CB implements IB, Serializable{
private final ID d;
public ID getD(){
return this.d;
}
}
public class CD implements ID, Serializable{
private DefaultMutableTreeNode rootNode;
public DefaultMutableTreeNode getRoot(){
return this.rootNode;
}
}
问题是,CA.FuncWithSpark() 中 DefaultMutableTreeNode 类型的变量发生了什么?是因为 Spark 转换,还是 DefaultMutableTreeNode 的成员变量受到保护而没有访问者?请给我一个解决这个问题的方向。感谢您提前提供任何帮助!