Java 注释的排序有什么约定吗?
对于大量使用Java注解的项目,对于注解顺序有什么建议吗?从而统一团队内的代码风格。
For projects heavily used of Java annotations, is there any suggestion on the annotation order? So as to uniform the code style in the team.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我要说没有。我可能在这一点上被证明是错误的。
我的理由是,除了 Java 中的项目和 IDE 中的项目(特别是 Eclipse,但我确信其他项目也有它们)之外,还有数百个项目具有注释。
因此,所有这些库都具有潜在的竞争性对于“谁在上面”,我怀疑他们会同意一个标准。
我鼓励您的团队坐下来做出对你们最有利的决定。
我会考虑的因素:
I'm going to say there's not. I could be proven wrong on this.
My reasoning is there are hundreds of projects that have annotations, in addition to the ones baked into Java, and the ones baked into our IDEs (specifically Eclipse but I'm sure others have them too.)
So, with all these libraries potentially competitng for "whose on top" I doubt they would agree on a standard.
I would encourage your team to sit down and make decisions about what's best for you guys.
Factors I would consider:
如果你必须强加一个顺序,按字母顺序?
如果不了解您正在使用的注释,就很难提出合理的排序建议。也许更好的排序更适合您和您的团队;如果是这样,如果您记录了商定的顺序,那么剩下的唯一事情就是验证它是否遵循团队商定的顺序。
与您的整个团队交谈后,您可能会发现您根本不需要订购它们。
If you must impose an order, alphabetical?
Without some sort of knowledge about the annotations you are using, it's hard to suggest a rational ordering. Perhaps a better ordering would suit you and your team better; and if so, if you document what's the agreed order, the only thing left is to verify it follows the team agreed ordering.
After talking to your whole team, you might find you don't need to order them after all.
这不是一门精确的科学,但我尝试将注释从顶部的“宽范围”排列到底部的“窄范围”。这是一个例子:
Not an exact science but I try to arrange annotations from a "wide scope" at the top to a "narrow scope" at the bottom. Here's an example: