我有一个界面
public interace ABC {
}
Run Code Online (Sandbox Code Playgroud)
其实现如下:
public class XYZ implements ABC {
private Map<String, String> mapValue;
public void setMapValue( Map<String, String> mapValue) {
this.mapValue = mapValue;
}
public Map<String, String> getMapValue() {
return this.mapValue
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用实现为的 Gson 反序列化一个类
public class UVW {
ABC abcObject;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试反序列化它时,gson.fromJson(jsonString, UVW.class);它会返回给我null。jsonString 是 UTF_8 字符串。
是不是因为 UVW 类中使用的接口?如果是,我如何反序列化这样的类?
我有以下伪代码,如果tree是binaryTree的实例,我需要更新计数器值.如果树有更多的孩子,我会递归调用该方法并递增计数器.
问题是如果我使计数器静态(我不想这样),计数器值很好但是当我将变量作为输入传递给方法时(如下所述)我只得到值1.什么是错的这里?
//Pseudo code
public static int test(tree) {
Integer count = 0;
return testTreeRecCounts(tree, count);
}
private static Integer testTreeRecursiveCounts(tree, Integer count) {
if (tree instanceof binaryTree) {
count++;
for (Node node :tree.getChild())) {
testTreeRecursiveCounts((tree)node, count);
}
}
return count;
}
Run Code Online (Sandbox Code Playgroud)