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

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

问题描述

我正在尝试在注释中创建一些信息树结构.经过一些尝试和帮助(参见 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 {};
}

这个节点应该允许我定义一级条件树.logicExpression 中的值定义了子节点(属性和另一个节点)之间的关系.问题是注解不允许递归依赖:

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

即使我将一些 NodeList 注释放入 Node 并且 NodeList 包含节点列表,也会再次识别循环依赖.

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?

推荐答案

这是因为这个 错误.

注解的继承性、多态性、'循环检测'限制是...线程讨论它.

您可以创建类似下面的内容

You can create Something like below

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


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

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

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