问题描述
给定下面的类,其中 Bar 的构造函数需要对 YAML 树中其祖先之一的引用 - 特别是对类 Foo 的最近祖先的引用:
是否可以使用 snakeYAML(或任何其他与 Java 兼容的解析器)实例化这些类?如果是这样,如何?
class Foo() {
private String firstName;
private String lastName;
private List<Bar> bars;
Foo() { // do something... }
// appropriate getters/setters here...
}
class Bar() {
private String label;
private String color;
private List<Bar> bars;
private List<Foo> foos;
Bar(Foo nearestAncestorFoo) { // nearestAncestorFoo should be a reference to the closest ancestor whose type is foo }
// appropriate getters/setters here...
}
示例 YAML 文件:
foos:
- firstName: Fred
lastName: Jones
bars:
- label: hello world
color: green
bars:
- label: globglob
color: blue
- label: mr. hankey
color: brown
foos:
- firstName: Dave
lastName : Davis
bars:
- label: Dave's only bar
color: beige
- name: bambam
color: grey
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)