“getDeclaredXyz"是什么?在 Java 反射包中代表 [英] What does the "getDeclaredXyz" stands for in Java reflect package

查看:31
本文介绍了“getDeclaredXyz"是什么?在 Java 反射包中代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:o.getClass().getDeclaredFields() vs. o.getClass().getFields();

声明的"是在当前源文件中声明的那些吗?

Are the "declared" those declared within the current source file?

推荐答案

getDeclaredFields():

返回一个 Field 对象数组,这些对象反映了此 Class 对象表示的类或接口声明的所有字段.这包括公共、受保护、默认(包)访问和私有字段,但不包括继承的字段.返回的数组中的元素没有排序,也没有任何特定的顺序.如果类或接口未声明任何字段,或者如果此 Class 对象表示原始类型、数组类或 void,则此方法返回长度为 0 的数组.

Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private fields, but excludes inherited fields. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface declares no fields, or if this Class object represents a primitive type, an array class, or void.

getFields():

返回一个包含 Field 对象的数组,这些对象反映了此 Class 对象表示的类或接口的所有可访问公共字段.返回的数组中的元素没有排序,也没有任何特定的顺序.如果类或接口没有可访问的公共字段,或者它表示数组类、基本类型或 void,则此方法返回长度为 0 的数组.具体来说,如果此 Class 对象表示一个类,则此方法返回该类及其所有超类的公共字段.如果此 Class 对象表示一个接口,则此方法返回此接口及其所有超接口的字段.

Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface has no accessible public fields, or if it represents an array class, a primitive type, or void. Specifically, if this Class object represents a class, this method returns the public fields of this class and of all its superclasses. If this Class object represents an interface, this method returns the fields of this interface and of all its superinterfaces.

这篇关于“getDeclaredXyz"是什么?在 Java 反射包中代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆