一个在构造函数上的注解,显示该构造函数的参数如何对应于构造对象的getter方法。例如:
public class Point {
@ConstructorProperties({"x", "y"})
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
private final int x, y;
}
该注解显示构造函数的第一个参数可以通过
getX()
方法检索,第二个参数可以通过
getY()
方法检索。由于参数名称通常在运行时不可用,如果没有该注解,将无法知道参数是与
getX()
和
getY()
对应,还是相反。
自Java版本:
1.6
Required Element Summary
Required Elements
Element Details
value
返回:
与带注解构造函数中的参数对应的获取器名称。
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation , which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy .