0
我正在使用snakeyml读取yml文件并将其加载到Java对象中。当构造函数参数传递时未创建Yaml实例
问题: 当我做Yaml yml = new Yaml()
时,创建了yml实例。但是当我传递构造函数参数时,不会创建yml实例。我也没有看到一个例外。这是完整的代码。在下面的语句
private static YamlConfig readStatsConfig()
throws IOException {
InputStream input = new FileInputStream(new File(configFile));
Constructor constructor = new Constructor(YamlConfig.class);
TypeDescription description = new TypeDescription(YamlConfig.class);
description.putListPropertyType("resources", YamlConfig.Resource.class);
constructor.addTypeDescription(description);
TypeDescription description = new TypeDescription(
YamlConfig.Resource.class);
description.putListPropertyType("stats", YamlConfig.StatsInfo.class);
constructor.addTypeDescription(description);
Yaml yaml = new Yaml(constructor);
YamlConfig cfg = (YamlConfig) yaml.load(input);
mainLogger.info(cfg);
return cfg;
}
代码退出:
Yaml yaml = new Yaml(constructor);
你是什么意思* “不创建实例” *? '新Yaml(构造函数)'将返回一个实例,否则会抛出一个异常。实际上没有其他可能的结果*(除非JVM本身崩溃)*。 – Andreas
我的意思是代码在语句中退出,Yaml yaml = new Yaml(构造函数)。我调试了代码以查看语句Yaml yaml1 = new Yaml()是否工作,并且它工作正常。我认为在创建的构造函数实例中存在一些问题,但是根据我的调试,我没有看到任何问题。是否有任何其他建议来实现相同的功能? – curious
*“声明中的代码退出”*是什么意思?由于异常,您的方法在那里停止运行?如果是这样,这个例外是什么意思? – Andreas