Sdílet prostřednictvím


Field.Get(Object) Method

Definition

Returns the value of the field represented by this Field, on the specified object.

[Android.Runtime.Register("get", "(Ljava/lang/Object;)Ljava/lang/Object;", "")]
public Java.Lang.Object? Get (Java.Lang.Object? obj);
[<Android.Runtime.Register("get", "(Ljava/lang/Object;)Ljava/lang/Object;", "")>]
member this.Get : Java.Lang.Object -> Java.Lang.Object

Parameters

obj
Object

object from which the represented field's value is to be extracted

Returns

the value of the represented field in object obj; primitive values are wrapped in an appropriate object before being returned

Attributes

Exceptions

if the object is null and the field is non-static

if the object is not compatible with the declaring class

if this field is not accessible

Remarks

Returns the value of the field represented by this Field, on the specified object. The value is automatically wrapped in an object if it has a primitive type.

The underlying field's value is obtained as follows:

If the underlying field is a static field, the obj argument is ignored; it may be null.

Otherwise, the underlying field is an instance field. If the specified obj argument is null, the method throws a NullPointerException. If the specified object is not an instance of the class or interface declaring the underlying field, the method throws an IllegalArgumentException.

If this Field object is enforcing Java language access control, and the underlying field is inaccessible, the method throws an IllegalAccessException. If the underlying field is static, the class that declared the field is initialized if it has not already been initialized.

Otherwise, the value is retrieved from the underlying instance or static field. If the field has a primitive type, the value is wrapped in an object before being returned, otherwise it is returned as is.

If the field is hidden in the type of obj, the field's value is obtained according to the preceding rules.

Java documentation for java.lang.reflect.Field.get(java.lang.Object).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to