【问题标题】:What is @constructorproperties? Is this belongs to J2SE or Spring?什么是@constructorproperties?这是属于 J2SE 还是 Spring?
【发布时间】:2020-01-23 03:47:58
【问题描述】:

什么是@ConstructorProperties?

我在谷歌上搜索但不明白那个。能解释一下吗?

谢谢。

【问题讨论】:

标签: java spring


【解决方案1】:

构造函数上的注释,显示该构造函数的参数如何对应于构造对象的 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() 或其他方式。

而且,@ConstructorProperties 来自属于 Java SE 的 java.beans 包

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 2016-11-14
    • 2013-06-15
    • 1970-01-01
    相关资源
    最近更新 更多