Java注释递归依赖性 [英] Java annotation recursive dependency

查看:199
本文介绍了Java注释递归依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建注释里面的一些信息树结构。经过一番tryings和帮助(见Java注解类型层次的),我搬到了下面的模型

I am trying to create some information tree structure inside annotations. After some tryings and helps (see Type hierarchy in java annotations) I moved to following model.

@interface Node {
  LogicalExpression logicalExpression() default LogicalExpression.AND;
  Attribute[] attributes() default {};
  Node[] nodes() default {};
}

此节点应允许我定义条件树的一个级别。 logicalEx pression内在价值定义儿童(属性和其它节点)之间的关系。问题是,标注不允许递归依赖性:

This node should allow me define one level of condition tree. Value inside logicalExpression defines relation between children (attributes and another nodes). Problem is that annotation does not allow recursive dependency:

Cycle detected: the annotation type Node cannot contain attributes of the annotation type itself

即使我把一些节点列表标注为节点,节点列表包含节点列表中的循环依赖被再次确认。

Even if I put some NodeList annotation into Node and NodeList contain list of Nodes the cyclic dependency is recognized again.

@interface NodeList {
  Node[] nodes();
}

@interface Node {
  LogicalExpression logicalExpression() default LogicalExpression.AND;
  Attribute[] attributes() default {};
  NodeList nodes() default EmptyList;
}

是否有循环注释定义任何解决方案?

Is there any solution on cyclic annotation definition?

推荐答案

这是因为这样的错误

注释继承,多态,循环检测限制是... 线程一下讨论。

您可以创建类似下面

@interface NodeInfo {
    LogicalExpression logicalExpression() default LogicalExpression.AND;
    Attribute[] attributes() default {};
}


@interface Node {
    NodeInfo[] nodes() default {};
}

这篇关于Java注释递归依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆