What does the “getDeclaredXyz” stands for in Java

2019-08-06 22:21发布

For instance: o.getClass().getDeclaredFields() vs. o.getClass().getFields();

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

1条回答
放荡不羁爱自由
2楼-- · 2019-08-06 22:45

getDeclaredFields():

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():

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.

查看更多
登录 后发表回答