Java Constructor getDeclaredAnnotations()方法及示例
java.lang.reflect.Constructor类 的 getDeclaredAnnotations() 方法用于返回存在于该Constructor元素上的注释,作为一个注释类对象的数组。getDeclaredAnnotations()方法忽略了这个构造函数对象上的继承注解。返回的数组可以不包含注解,如果构造函数有nop注解,则该数组的长度可以为0。
语法
参数: 此方法不接受任何东西。
返回 :该方法返回直接存在于该元素上的 注释数组 。
以下程序说明了getDeclaredAnnotations()方法:
程序1 :
输出。
程序2
输出。
参考文献: https://docs.oracle.com/javase/10/docs/api/java/lang/reflect/Constructor.html#getDeclaredAnnotations()