【发布时间】:2014-11-02 19:53:27
【问题描述】:
关于@ConstructorProperties
Documentation 表示“构造函数上的注释,显示该构造函数的参数如何对应于构造对象的 getter 方法”。它给出了一个模棱两可的例子,因为变量名称与参数相同。
我真的不明白为什么@ConstructorProperties({"x", "y"}) 指的是吸气剂getX() 和getY()。 x和y的大小写与注解不一致。
所以要澄清这段代码中构造函数的注释应该是什么:
public class Point {
public Point(int a, int b) {
this.c = a;
this.d = b;
}
public int getCc() {
return c;
}
public int getDd() {
return d;
}
private final int c, d;
}
(我编辑了代码,因为从答案中,我理解注释希望代码遵循 getter 的常见大小写约定,例如 cc getter 必须是 getCc()。但为了消除歧义,我故意保留差异在 getter 名称和返回的实际变量之间)
第二个问题……
@ConstructorProperties(value="text")
这个注解对于JButton(String text)意味着什么?
好像是供工具使用的,只是想了解一下。
【问题讨论】:
标签: java constructor annotations