1 |
/* |
/* java.lang.reflect.Field - reflection of Java fields |
2 |
* java.lang.reflect.Field: part of the Java Class Libraries project. |
Copyright (C) 1998, 2001 Free Software Foundation, Inc. |
3 |
* Copyright (C) 1998 Free Software Foundation |
|
4 |
* |
This file is part of GNU Classpath. |
5 |
* This library is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU Library General Public |
GNU Classpath is free software; you can redistribute it and/or modify |
7 |
* License as published by the Free Software Foundation; either |
it under the terms of the GNU General Public License as published by |
8 |
* version 2 of the License, or (at your option) any later version. |
the Free Software Foundation; either version 2, or (at your option) |
9 |
* |
any later version. |
10 |
* This library is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
GNU Classpath is distributed in the hope that it will be useful, but |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* Library General Public License for more details. |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
* |
General Public License for more details. |
15 |
* You should have received a copy of the GNU Library General Public |
|
16 |
* License along with this library; if not, write to the |
You should have received a copy of the GNU General Public License |
17 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
along with GNU Classpath; see the file COPYING. If not, write to the |
18 |
* Boston, MA 02111-1307, USA. |
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
19 |
*/ |
02111-1307 USA. |
20 |
|
|
21 |
|
As a special exception, if you link this library with other files to |
22 |
|
produce an executable, this library does not by itself cause the |
23 |
|
resulting executable to be covered by the GNU General Public License. |
24 |
|
This exception does not however invalidate any other reasons why the |
25 |
|
executable file might be covered by the GNU General Public License. */ |
26 |
|
|
27 |
|
|
28 |
package java.lang.reflect; |
package java.lang.reflect; |
29 |
|
|
30 |
/** |
/** |
31 |
** The Field class represents a member variable of a class. |
* The Field class represents a member variable of a class. It also allows |
32 |
** It allows you to read and manipulate that variable.<P> |
* dynamic access to a member, via reflection. This works for both |
33 |
** |
* static and instance fields. Operations on Field objects know how to |
34 |
** <B>Note:</B> This class returns and accepts types as Classes, even primitive types; there are Class |
* do widening conversions, but throw {@link IllegalArgumentException} if |
35 |
** types defined that represent each different primitive type. They are <code>java.lang.Boolean.TYPE, |
* a narrowing conversion would be necessary. You can query for information |
36 |
** java.lang.Byte.TYPE, </code>etc. These are not to be confused with the classes |
* on this Field regardless of location, but get and set access may be limited |
37 |
** <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are real classes.<P> |
* by Java language access controls. If you can't do it in the compiler, you |
38 |
** |
* can't normally do it here either.<p> |
39 |
** Also note that this is not a serializable class. It is entirely feasible to make it serializable |
* |
40 |
** using the Externalizable interface, but this is on Sun, not me. |
* <B>Note:</B> This class returns and accepts types as Classes, even |
41 |
** |
* primitive types; there are Class types defined that represent each |
42 |
** @author John Keiser |
* different primitive type. They are <code>java.lang.Boolean.TYPE, |
43 |
** @version 1.1.0, 31 May 1998 |
* java.lang.Byte.TYPE,</code>, also available as <code>boolean.class, |
44 |
** @see Member |
* byte.class</code>, etc. These are not to be confused with the |
45 |
** @see java.lang.Class#getField(String) |
* classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are |
46 |
** @see java.lang.Class#getDeclaredField(String) |
* real classes.<p> |
47 |
** @see java.lang.Class#getFields() |
* |
48 |
** @see java.lang.Class#getDeclaredFields() |
* Also note that this is not a serializable class. It is entirely feasible |
49 |
**/ |
* to make it serializable using the Externalizable interface, but this is |
50 |
public final class Field implements Member { |
* on Sun, not me. |
51 |
private Class declaringClass; |
* |
52 |
private String name; |
* @author John Keiser |
53 |
private int slot; |
* @author Eric Blake <ebb9@email.byu.edu> |
54 |
|
* @see Member |
55 |
/* This class is uninstantiable except natively. */ |
* @see Class |
56 |
private Field(Class declaringClass, String name, int slot) { |
* @see Class#getField(String) |
57 |
this.declaringClass = declaringClass; |
* @see Class#getDeclaredField(String) |
58 |
this.name = name; |
* @see Class#getFields() |
59 |
this.slot = slot; |
* @see Class#getDeclaredFields() |
60 |
} |
* @since 1.1 |
61 |
|
* @status updated to 1.4 |
62 |
/** Gets the class that declared this field. |
*/ |
63 |
** <B>It is unclear whether this returns the class that actually syntactically declared |
public final class Field |
64 |
** the member, or the class where the Field object was gotten from.</B> |
extends AccessibleObject implements Member |
65 |
** @return the class that declared this member. |
{ |
66 |
**/ |
private Class declaringClass; |
67 |
public Class getDeclaringClass() { |
private String name; |
68 |
return declaringClass; |
private int slot; |
69 |
} |
|
70 |
|
/** |
71 |
/** Gets the modifiers this field uses. Use the <code>Modifier</code> |
* This class is uninstantiable except natively. |
72 |
** class to interpret the values. A field can only have the following |
*/ |
73 |
** modifiers: public, private, protected, static, final, transient, and volatile. |
private Field(Class declaringClass, String name, int slot) |
74 |
** @see Modifier |
{ |
75 |
** @return an integer representing the modifiers to this Member. |
this.declaringClass = declaringClass; |
76 |
**/ |
this.name = name; |
77 |
public native int getModifiers(); |
this.slot = slot; |
78 |
|
} |
79 |
/** Gets the name of this field. |
|
80 |
** @return the name of this field. |
/** |
81 |
**/ |
* Gets the class that declared this field, or the class where this field |
82 |
public String getName() { |
* is a non-inherited member. |
83 |
return name; |
* @return the class that declared this member |
84 |
} |
*/ |
85 |
|
public Class getDeclaringClass() |
86 |
/** Gets the type of this field. |
{ |
87 |
** @return the type of this field. |
return declaringClass; |
88 |
**/ |
} |
89 |
public native Class getType(); |
|
90 |
|
/** |
91 |
/** Compare two objects to see if they are semantically equivalent. |
* Gets the name of this field. |
92 |
** Two Fields are semantically equivalent if they have the same declaring class and the |
* @return the name of this field |
93 |
** same name. |
*/ |
94 |
** @param o the object to compare to. |
public String getName() |
95 |
** @return <code>true</code> if they are equal; <code>false</code> if not. |
{ |
96 |
**/ |
return name; |
97 |
public boolean equals(Object o) { |
} |
98 |
return this == o; |
|
99 |
} |
/** |
100 |
|
* Gets the modifiers this field uses. Use the <code>Modifier</code> |
101 |
/** Get the hash code for the Field. |
* class to interpret the values. A field can only have a subset of the |
102 |
** The Field hash code is the hash code of its name XOR'd with the hash code of its class name. |
* following modifiers: public, private, protected, static, final, |
103 |
** @return the hash code for the object. |
* transient, and volatile. |
104 |
**/ |
* |
105 |
public int hashCode() { |
* @return an integer representing the modifiers to this Member |
106 |
return getDeclaringClass().getName().hashCode() ^ getName().hashCode(); |
* @see Modifier |
107 |
} |
*/ |
108 |
|
public native int getModifiers(); |
109 |
/** Get a String representation of the Field. |
|
110 |
** A Field's String representation is <modifiers> <type> <class>.<fieldname>. |
/** |
111 |
** Example: <code>public transient boolean gnu.parse.Parser.parseComplete</code> |
* Gets the type of this field. |
112 |
** @return the String representation of the Constructor. |
* @return the type of this field |
113 |
**/ |
*/ |
114 |
public String toString() { |
public native Class getType(); |
115 |
StringBuffer sb = new StringBuffer(); |
|
116 |
sb.append(Modifier.toString(getModifiers())); |
/** |
117 |
sb.append(' '); |
* Compare two objects to see if they are semantically equivalent. |
118 |
sb.append(getType().getName()); |
* Two Fields are semantically equivalent if they have the same declaring |
119 |
sb.append(' '); |
* class, name, and type. Since you can't creat a Field except through |
120 |
sb.append(getDeclaringClass().getName()); |
* the VM, this is just the == relation. |
121 |
sb.append('.'); |
* |
122 |
sb.append(getName()); |
* @param o the object to compare to |
123 |
return sb.toString(); |
* @return <code>true</code> if they are equal; <code>false</code> if not |
124 |
} |
*/ |
125 |
|
public boolean equals(Object o) |
126 |
|
{ |
127 |
|
return this == o; |
128 |
|
} |
129 |
|
|
130 |
|
/** |
131 |
|
* Get the hash code for the Field. The Field hash code is the hash code |
132 |
|
* of its name XOR'd with the hash code of its class name. |
133 |
|
* |
134 |
|
* @return the hash code for the object. |
135 |
|
*/ |
136 |
|
public int hashCode() |
137 |
|
{ |
138 |
|
return getDeclaringClass().getName().hashCode() ^ getName().hashCode(); |
139 |
|
} |
140 |
|
|
141 |
|
/** |
142 |
|
* Get a String representation of the Field. A Field's String |
143 |
|
* representation is "<modifiers> <type> |
144 |
|
* <class>.<fieldname>".<br> Example: |
145 |
|
* <code>public transient boolean gnu.parse.Parser.parseComplete</code> |
146 |
|
* |
147 |
|
* @return the String representation of the Field |
148 |
|
*/ |
149 |
|
public String toString() |
150 |
|
{ |
151 |
|
StringBuffer sb = new StringBuffer(); |
152 |
|
Modifier.toString(getModifiers(), sb).append(' '); |
153 |
|
sb.append(getType().getName()).append(' '); |
154 |
|
sb.append(getDeclaringClass().getName()).append('.'); |
155 |
|
sb.append(getName()); |
156 |
|
return sb.toString(); |
157 |
|
} |
158 |
|
|
159 |
/** Get the value of this Field. If it is primitive, it will be wrapped in the |
/** |
160 |
** appropriate wrapper type (boolean = java.lang.Boolean) |
* Get the value of this Field. If it is primitive, it will be wrapped |
161 |
** If the field is static, <code>o</code> will be ignored. |
* in the appropriate wrapper type (boolean = java.lang.Boolean).<p> |
162 |
** @param o the object to get the value of this Field from. |
* |
163 |
** @return the value of the Field. |
* If the field is static, <code>o</code> will be ignored. Otherwise, if |
164 |
** @exception IllegalAccessException if you could not normally access this field |
* <code>o</code> is null, you get a <code>NullPointerException</code>, |
165 |
** (i.e. it is not public). |
* and if it is incompatible with the declaring class of the field, you |
166 |
** @exception IllegalArgumentException if this field is not a field of <code>o</code>. |
* get an <code>IllegalArgumentException</code>.<p> |
167 |
**/ |
* |
168 |
public native Object get(Object o) |
* Next, if this Field enforces access control, your runtime context is |
169 |
throws IllegalAccessException, |
* evaluated, and you may have an <code>IllegalAccessException</code> if |
170 |
IllegalArgumentException; |
* you could not access this field in similar compiled code. If the field |
171 |
|
* is static, and its class is uninitialized, you trigger class |
172 |
/** Get the value of this boolean Field. |
* initialization, which may end in a |
173 |
** If the field is static, <code>o</code> will be ignored. |
* <code>ExceptionInInitializerError</code>.<p> |
174 |
** @param o the object to get the value of this Field from. |
* |
175 |
** @return the value of the Field. |
* Finally, the field is accessed, and primitives are wrapped (but not |
176 |
** @exception IllegalAccessException if you could not normally access this field |
* necessarily in new objects). This method accesses the field of the |
177 |
** (i.e. it is not public). |
* declaring class, even if the instance passed in belongs to a subclass |
178 |
** @exception IllegalArgumentException if this is not a boolean field of <code>o</code>. |
* which declares another field to hide this one. |
179 |
**/ |
* |
180 |
public native boolean getBoolean(Object o) |
* @param o the object to get the value of this Field from |
181 |
throws IllegalAccessException, |
* @return the value of the Field |
182 |
IllegalArgumentException; |
* @throws IllegalAccessException if you could not normally access this field |
183 |
|
* (i.e. it is not public) |
184 |
/** Get the value of this byte Field. |
* @throws IllegalArgumentException if <code>o</code> is not an instance of |
185 |
** If the field is static, <code>o</code> will be ignored. |
* the class or interface declaring this field |
186 |
** @param o the object to get the value of this Field from. |
* @throws NullPointerException if <code>o</code> is null and this field |
187 |
** @return the value of the Field. |
* requires an instance |
188 |
** @exception IllegalAccessException if you could not normally access this field |
* @throws ExceptionInInitializerError if accessing a static field triggered |
189 |
** (i.e. it is not public). |
* class initialization, which then failed |
190 |
** @exception IllegalArgumentException if this is not a byte field of <code>o</code>. |
* @see #getBoolean(Object) |
191 |
**/ |
* @see #getByte(Object) |
192 |
public native byte getByte(Object o) |
* @see #getChar(Object) |
193 |
throws IllegalAccessException, |
* @see #getShort(Object) |
194 |
IllegalArgumentException; |
* @see #getInt(Object) |
195 |
|
* @see #getLong(Object) |
196 |
/** Get the value of this Field as a short. |
* @see #getFloat(Object) |
197 |
** If the field is static, <code>o</code> will be ignored. |
* @see #getDouble(Object) |
198 |
** @param o the object to get the value of this Field from. |
*/ |
199 |
** @return the value of the Field. |
public native Object get(Object o) |
200 |
** @exception IllegalAccessException if you could not normally access this field |
throws IllegalAccessException; |
201 |
** (i.e. it is not public). |
|
202 |
** @exception IllegalArgumentException if this is not a field of <code>o</code> or is |
/** |
203 |
** a field of <code>o</code> but cannot be converted |
* Get the value of this boolean Field. If the field is static, |
204 |
** via a widening conversion to a short. |
* <code>o</code> will be ignored. |
205 |
**/ |
* |
206 |
public native short getShort(Object o) |
* @param o the object to get the value of this Field from |
207 |
throws IllegalAccessException, |
* @return the value of the Field |
208 |
IllegalArgumentException; |
* @throws IllegalAccessException if you could not normally access this field |
209 |
|
* (i.e. it is not public) |
210 |
/** Get the value of this Field as a char. |
* @throws IllegalArgumentException if this is not a boolean field of |
211 |
** If the field is static, <code>o</code> will be ignored. |
* <code>o</code>, or if <code>o</code> is not an instance of the |
212 |
** @param o the object to get the value of this Field from. |
* declaring class of this field |
213 |
** @return the value of the Field. |
* @throws NullPointerException if <code>o</code> is null and this field |
214 |
** @exception IllegalAccessException if you could not normally access this field |
* requires an instance |
215 |
** (i.e. it is not public). |
* @throws ExceptionInInitializerError if accessing a static field triggered |
216 |
** @exception IllegalArgumentException if this is not a field of <code>o</code> or is |
* class initialization, which then failed |
217 |
** a field of <code>o</code> but cannot be converted |
* @see #get(Object) |
218 |
** via a widening conversion to a char. |
*/ |
219 |
**/ |
public native boolean getBoolean(Object o) |
220 |
public native char getChar(Object o) |
throws IllegalAccessException; |
221 |
throws IllegalAccessException, |
|
222 |
IllegalArgumentException; |
/** |
223 |
|
* Get the value of this byte Field. If the field is static, |
224 |
/** Get the value of this Field as an int. |
* <code>o</code> will be ignored. |
225 |
** If the field is static, <code>o</code> will be ignored. |
* |
226 |
** @param o the object to get the value of this Field from. |
* @param o the object to get the value of this Field from |
227 |
** @return the value of the Field. |
* @return the value of the Field |
228 |
** @exception IllegalAccessException if you could not normally access this field |
* @throws IllegalAccessException if you could not normally access this field |
229 |
** (i.e. it is not public). |
* (i.e. it is not public) |
230 |
** @exception IllegalArgumentException if this is not a field of <code>o</code> or is |
* @throws IllegalArgumentException if this is not a byte field of |
231 |
** a field of <code>o</code> but cannot be converted |
* <code>o</code>, or if <code>o</code> is not an instance of the |
232 |
** via a widening conversion to an int. |
* declaring class of this field |
233 |
**/ |
* @throws NullPointerException if <code>o</code> is null and this field |
234 |
public native int getInt(Object o) |
* requires an instance |
235 |
throws IllegalAccessException, |
* @throws ExceptionInInitializerError if accessing a static field triggered |
236 |
IllegalArgumentException; |
* class initialization, which then failed |
237 |
|
* @see #get(Object) |
238 |
/** Get the value of this Field as a long. |
*/ |
239 |
** If the field is static, <code>o</code> will be ignored. |
public native byte getByte(Object o) |
240 |
** @param o the object to get the value of this Field from. |
throws IllegalAccessException; |
241 |
** @return the value of the Field. |
|
242 |
** @exception IllegalAccessException if you could not normally access this field |
/** |
243 |
** (i.e. it is not public). |
* Get the value of this Field as a char. If the field is static, |
244 |
** @exception IllegalArgumentException if this is not a field of <code>o</code> or is |
* <code>o</code> will be ignored. |
245 |
** a field of <code>o</code> but cannot be converted |
* |
246 |
** via a widening conversion to a long. |
* @throws IllegalAccessException if you could not normally access this field |
247 |
**/ |
* (i.e. it is not public) |
248 |
public native long getLong(Object o) |
* @throws IllegalArgumentException if this is not a char field of |
249 |
throws IllegalAccessException, |
* <code>o</code>, or if <code>o</code> is not an instance |
250 |
IllegalArgumentException; |
* of the declaring class of this field |
251 |
|
* @throws NullPointerException if <code>o</code> is null and this field |
252 |
/** Get the value of this Field as a float. |
* requires an instance |
253 |
** If the field is static, <code>o</code> will be ignored. |
* @throws ExceptionInInitializerError if accessing a static field triggered |
254 |
** @param o the object to get the value of this Field from. |
* class initialization, which then failed |
255 |
** @return the value of the Field. |
* @see #get(Object) |
256 |
** @exception IllegalAccessException if you could not normally access this field |
*/ |
257 |
** (i.e. it is not public). |
public native char getChar(Object o) |
258 |
** @exception IllegalArgumentException if this is not a field of <code>o</code> or is |
throws IllegalAccessException; |
259 |
** a field of <code>o</code> but cannot be converted |
|
260 |
** via a widening conversion to a float. |
/** |
261 |
**/ |
* Get the value of this Field as a short. If the field is static, |
262 |
public native float getFloat(Object o) |
* <code>o</code> will be ignored. |
263 |
throws IllegalAccessException, |
* |
264 |
IllegalArgumentException; |
* @param o the object to get the value of this Field from |
265 |
|
* @return the value of the Field |
266 |
/** Get the value of this Field as a double. |
* @throws IllegalAccessException if you could not normally access this field |
267 |
** If the field is static, <code>o</code> will be ignored. |
* (i.e. it is not public) |
268 |
** @param o the object to get the value of this Field from. |
* @throws IllegalArgumentException if this is not a byte or short |
269 |
** @return the value of the Field. |
* field of <code>o</code>, or if <code>o</code> is not an instance |
270 |
** @exception IllegalAccessException if you could not normally access this field |
* of the declaring class of this field |
271 |
** (i.e. it is not public). |
* @throws NullPointerException if <code>o</code> is null and this field |
272 |
** @exception IllegalArgumentException if this is not a field of <code>o</code> or is |
* requires an instance |
273 |
** a field of <code>o</code> but cannot be converted |
* @throws ExceptionInInitializerError if accessing a static field triggered |
274 |
** via a widening conversion to a double. |
* class initialization, which then failed |
275 |
**/ |
* @see #get(Object) |
276 |
public native double getDouble(Object o) |
*/ |
277 |
throws IllegalAccessException, |
public native short getShort(Object o) |
278 |
IllegalArgumentException; |
throws IllegalAccessException; |
279 |
|
|
280 |
/** Set this Field. If it is a primitive field, the value passed must be wrapped in |
/** |
281 |
** the appropriate wrapped type (boolean = java.lang.Boolean) |
* Get the value of this Field as an int. If the field is static, |
282 |
** If the field is static, <code>o</code> will be ignored. |
* <code>o</code> will be ignored. |
283 |
** @param o the object to set this Field on. |
* |
284 |
** @param value the value to set this Field to. |
* @param o the object to get the value of this Field from |
285 |
** @exception IllegalAccessException if you could not normally access this field |
* @return the value of the Field |
286 |
** (i.e. it is not public). |
* @throws IllegalAccessException if you could not normally access this field |
287 |
** @exception IllegalArgumentException if <code>value</code> cannot be converted by a |
* (i.e. it is not public) |
288 |
** widening conversion to the underlying type of |
* @throws IllegalArgumentException if this is not a byte, short, char, or |
289 |
** the Field. |
* int field of <code>o</code>, or if <code>o</code> is not an |
290 |
**/ |
* instance of the declaring class of this field |
291 |
public native void set(Object o, Object value) |
* @throws NullPointerException if <code>o</code> is null and this field |
292 |
throws IllegalAccessException, |
* requires an instance |
293 |
IllegalArgumentException; |
* @throws ExceptionInInitializerError if accessing a static field triggered |
294 |
|
* class initialization, which then failed |
295 |
/** Set this boolean Field. |
* @see #get(Object) |
296 |
** If the field is static, <code>o</code> will be ignored. |
*/ |
297 |
** @param o the object to set this Field on. |
public native int getInt(Object o) |
298 |
** @param value the value to set this Field to. |
throws IllegalAccessException; |
299 |
** @exception IllegalAccessException if you could not normally access this field |
|
300 |
** (i.e. it is not public). |
/** |
301 |
** @exception IllegalArgumentException if this field is not a primitive boolean field. |
* Get the value of this Field as a long. If the field is static, |
302 |
**/ |
* <code>o</code> will be ignored. |
303 |
public native void setBoolean(Object o, boolean value) |
* |
304 |
throws IllegalAccessException, |
* @param o the object to get the value of this Field from |
305 |
IllegalArgumentException; |
* @return the value of the Field |
306 |
|
* @throws IllegalAccessException if you could not normally access this field |
307 |
/** Set this byte Field. |
* (i.e. it is not public) |
308 |
** If the field is static, <code>o</code> will be ignored. |
* @throws IllegalArgumentException if this is not a byte, short, char, int, |
309 |
** @param o the object to set this Field on. |
* or long field of <code>o</code>, or if <code>o</code> is not an |
310 |
** @param value the value to set this Field to. |
* instance of the declaring class of this field |
311 |
** @exception IllegalAccessException if you could not normally access this field |
* @throws NullPointerException if <code>o</code> is null and this field |
312 |
** (i.e. it is not public). |
* requires an instance |
313 |
** @exception IllegalArgumentException if a byte cannot be converted via a widening |
* @throws ExceptionInInitializerError if accessing a static field triggered |
314 |
** conversion to the type of this field. |
* class initialization, which then failed |
315 |
**/ |
* @see #get(Object) |
316 |
public native void setByte(Object o, byte value) |
*/ |
317 |
throws IllegalAccessException, |
public native long getLong(Object o) |
318 |
IllegalArgumentException; |
throws IllegalAccessException; |
319 |
|
|
320 |
/** Set this short Field. |
/** |
321 |
** If the field is static, <code>o</code> will be ignored. |
* Get the value of this Field as a float. If the field is static, |
322 |
** @param o the object to set this Field on. |
* <code>o</code> will be ignored. |
323 |
** @param value the value to set this Field to. |
* |
324 |
** @exception IllegalAccessException if you could not normally access this field |
* @param o the object to get the value of this Field from |
325 |
** (i.e. it is not public). |
* @return the value of the Field |
326 |
** @exception IllegalArgumentException if a byte cannot be converted via a widening |
* @throws IllegalAccessException if you could not normally access this field |
327 |
** conversion to the type of this field. |
* (i.e. it is not public) |
328 |
**/ |
* @throws IllegalArgumentException if this is not a byte, short, char, int, |
329 |
public native void setShort(Object o, short value) |
* long, or float field of <code>o</code>, or if <code>o</code> is |
330 |
throws IllegalAccessException, |
* not an instance of the declaring class of this field |
331 |
IllegalArgumentException; |
* @throws NullPointerException if <code>o</code> is null and this field |
332 |
|
* requires an instance |
333 |
/** Set this char Field. |
* @throws ExceptionInInitializerError if accessing a static field triggered |
334 |
** If the field is static, <code>o</code> will be ignored. |
* class initialization, which then failed |
335 |
** @param o the object to set this Field on. |
* @see #get(Object) |
336 |
** @param value the value to set this Field to. |
*/ |
337 |
** @exception IllegalAccessException if you could not normally access this field |
public native float getFloat(Object o) |
338 |
** (i.e. it is not public). |
throws IllegalAccessException; |
339 |
** @exception IllegalArgumentException if a char cannot be converted via a widening |
|
340 |
** conversion to the type of this field. |
/** |
341 |
**/ |
* Get the value of this Field as a double. If the field is static, |
342 |
public native void setChar(Object o, char value) |
* <code>o</code> will be ignored. |
343 |
throws IllegalAccessException, |
* |
344 |
IllegalArgumentException; |
* @param o the object to get the value of this Field from |
345 |
|
* @return the value of the Field |
346 |
/** Set this int Field. |
* @throws IllegalAccessException if you could not normally access this field |
347 |
** If the field is static, <code>o</code> will be ignored. |
* (i.e. it is not public) |
348 |
** @param o the object to set this Field on. |
* @throws IllegalArgumentException if this is not a byte, short, char, int, |
349 |
** @param value the value to set this Field to. |
* long, float, or double field of <code>o</code>, or if |
350 |
** @exception IllegalAccessException if you could not normally access this field |
* <code>o</code> is not an instance of the declaring class of this |
351 |
** (i.e. it is not public). |
* field |
352 |
** @exception IllegalArgumentException if an int cannot be converted via a widening |
* @throws NullPointerException if <code>o</code> is null and this field |
353 |
** conversion to the type of this field. |
* requires an instance |
354 |
**/ |
* @throws ExceptionInInitializerError if accessing a static field triggered |
355 |
public native void setInt(Object o, int value) |
* class initialization, which then failed |
356 |
throws IllegalAccessException, |
* @see #get(Object) |
357 |
IllegalArgumentException; |
*/ |
358 |
|
public native double getDouble(Object o) |
359 |
/** Set this long Field. |
throws IllegalAccessException; |
360 |
** If the field is static, <code>o</code> will be ignored. |
|
361 |
** @param o the object to set this Field on. |
/** |
362 |
** @param value the value to set this Field to. |
* Set the value of this Field. If it is a primitive field, the value |
363 |
** @exception IllegalAccessException if you could not normally access this field |
* will be unwrapped from the passed object (boolean = java.lang.Boolean).<p> |
364 |
** (i.e. it is not public). |
* |
365 |
** @exception IllegalArgumentException if a long cannot be converted via a widening |
* If the field is static, <code>o</code> will be ignored. Otherwise, if |
366 |
** conversion to the type of this field. |
* <code>o</code> is null, you get a <code>NullPointerException</code>, |
367 |
**/ |
* and if it is incompatible with the declaring class of the field, you |
368 |
public native void setLong(Object o, long value) |
* get an <code>IllegalArgumentException</code>.<p> |
369 |
throws IllegalAccessException, |
* |
370 |
IllegalArgumentException; |
* Next, if this Field enforces access control, your runtime context is |
371 |
|
* evaluated, and you may have an <code>IllegalAccessException</code> if |
372 |
/** Set this float Field. |
* you could not access this field in similar compiled code. This also |
373 |
** If the field is static, <code>o</code> will be ignored. |
* occurs whether or not there is access control if the field is final. |
374 |
** @param o the object to set this Field on. |
* If the field is primitive, and unwrapping your argument fails, you will |
375 |
** @param value the value to set this Field to. |
* get an <code>IllegalArgumentException</code>; likewise, this error |
376 |
** @exception IllegalAccessException if you could not normally access this field |
* happens if <code>value</code> cannot be cast to the correct object type. |
377 |
** (i.e. it is not public). |
* If the field is static, and its class is uninitialized, you trigger class |
378 |
** @exception IllegalArgumentException if a float cannot be converted via a widening |
* initialization, which may end in a |
379 |
** conversion to the type of this field. |
* <code>ExceptionInInitializerError</code>.<p> |
380 |
**/ |
* |
381 |
public native void setFloat(Object o, float value) |
* Finally, the field is set with the widened value. This method accesses |
382 |
throws IllegalAccessException, |
* the field of the declaring class, even if the instance passed in belongs |
383 |
IllegalArgumentException; |
* to a subclass which declares another field to hide this one. |
384 |
|
* |
385 |
/** Set this double Field. |
* @param o the object to set this Field on |
386 |
** If the field is static, <code>o</code> will be ignored. |
* @param value the value to set this Field to |
387 |
** @param o the object to set this Field on. |
* @throws IllegalAccessException if you could not normally access this field |
388 |
** @param value the value to set this Field to |
* (i.e. it is not public) |
389 |
** @exception IllegalAccessException if you could not normally access this field |
* @throws IllegalArgumentException if <code>value</code> cannot be |
390 |
** (i.e. it is not public). |
* converted by a widening conversion to the underlying type of |
391 |
** @exception IllegalArgumentException if this field is not a primitive double field. |
* the Field, or if <code>o</code> is not an instance of the class |
392 |
**/ |
* declaring this field |
393 |
public native void setDouble(Object o, double value) |
* @throws NullPointerException if <code>o</code> is null and this field |
394 |
throws IllegalAccessException, |
* requires an instance |
395 |
IllegalArgumentException; |
* @throws ExceptionInInitializerError if accessing a static field triggered |
396 |
|
* class initialization, which then failed |
397 |
|
* @see #setBoolean(Object, boolean) |
398 |
|
* @see #setByte(Object, byte) |
399 |
|
* @see #setChar(Object, char) |
400 |
|
* @see #setShort(Object, short) |
401 |
|
* @see #setInt(Object, int) |
402 |
|
* @see #setLong(Object, long) |
403 |
|
* @see #setFloat(Object, float) |
404 |
|
* @see #setDouble(Object, double) |
405 |
|
*/ |
406 |
|
public native void set(Object o, Object value) |
407 |
|
throws IllegalAccessException; |
408 |
|
|
409 |
|
/** |
410 |
|
* Set this boolean Field. If the field is static, <code>o</code> will be |
411 |
|
* ignored. |
412 |
|
* |
413 |
|
* @param o the object to set this Field on |
414 |
|
* @param value the value to set this Field to |
415 |
|
* @throws IllegalAccessException if you could not normally access this field |
416 |
|
* (i.e. it is not public) |
417 |
|
* @throws IllegalArgumentException if this is not a boolean field, or if |
418 |
|
* <code>o</code> is not an instance of the class declaring this |
419 |
|
* field |
420 |
|
* @throws NullPointerException if <code>o</code> is null and this field |
421 |
|
* requires an instance |
422 |
|
* @throws ExceptionInInitializerError if accessing a static field triggered |
423 |
|
* class initialization, which then failed |
424 |
|
* @see #set(Object, Object) |
425 |
|
*/ |
426 |
|
public native void setBoolean(Object o, boolean value) |
427 |
|
throws IllegalAccessException; |
428 |
|
|
429 |
|
/** |
430 |
|
* Set this byte Field. If the field is static, <code>o</code> will be |
431 |
|
* ignored. |
432 |
|
* |
433 |
|
* @param o the object to set this Field on |
434 |
|
* @param value the value to set this Field to |
435 |
|
* @throws IllegalAccessException if you could not normally access this field |
436 |
|
* (i.e. it is not public) |
437 |
|
* @throws IllegalArgumentException if this is not a byte, short, int, long, |
438 |
|
* float, or double field, or if <code>o</code> is not an instance |
439 |
|
* of the class declaring this field |
440 |
|
* @throws NullPointerException if <code>o</code> is null and this field |
441 |
|
* requires an instance |
442 |
|
* @throws ExceptionInInitializerError if accessing a static field triggered |
443 |
|
* class initialization, which then failed |
444 |
|
* @see #set(Object, Object) |
445 |
|
*/ |
446 |
|
public native void setByte(Object o, byte value) |
447 |
|
throws IllegalAccessException; |
448 |
|
|
449 |
|
/** |
450 |
|
* Set this char Field. If the field is static, <code>o</code> will be |
451 |
|
* ignored. |
452 |
|
* |
453 |
|
* @param o the object to set this Field on |
454 |
|
* @param value the value to set this Field to |
455 |
|
* @throws IllegalAccessException if you could not normally access this field |
456 |
|
* (i.e. it is not public) |
457 |
|
* @throws IllegalArgumentException if this is not a char, int, long, |
458 |
|
* float, or double field, or if <code>o</code> is not an instance |
459 |
|
* of the class declaring this field |
460 |
|
* @throws NullPointerException if <code>o</code> is null and this field |
461 |
|
* requires an instance |
462 |
|
* @throws ExceptionInInitializerError if accessing a static field triggered |
463 |
|
* class initialization, which then failed |
464 |
|
* @see #set(Object, Object) |
465 |
|
*/ |
466 |
|
public native void setChar(Object o, char value) |
467 |
|
throws IllegalAccessException; |
468 |
|
|
469 |
|
/** |
470 |
|
* Set this short Field. If the field is static, <code>o</code> will be |
471 |
|
* ignored. |
472 |
|
* |
473 |
|
* @param o the object to set this Field on |
474 |
|
* @param value the value to set this Field to |
475 |
|
* @throws IllegalAccessException if you could not normally access this field |
476 |
|
* (i.e. it is not public) |
477 |
|
* @throws IllegalArgumentException if this is not a short, int, long, |
478 |
|
* float, or double field, or if <code>o</code> is not an instance |
479 |
|
* of the class declaring this field |
480 |
|
* @throws NullPointerException if <code>o</code> is null and this field |
481 |
|
* requires an instance |
482 |
|
* @throws ExceptionInInitializerError if accessing a static field triggered |
483 |
|
* class initialization, which then failed |
484 |
|
* @see #set(Object, Object) |
485 |
|
*/ |
486 |
|
public native void setShort(Object o, short value) |
487 |
|
throws IllegalAccessException; |
488 |
|
|
489 |
|
/** |
490 |
|
* Set this int Field. If the field is static, <code>o</code> will be |
491 |
|
* ignored. |
492 |
|
* |
493 |
|
* @param o the object to set this Field on |
494 |
|
* @param value the value to set this Field to |
495 |
|
* @throws IllegalAccessException if you could not normally access this field |
496 |
|
* (i.e. it is not public) |
497 |
|
* @throws IllegalArgumentException if this is not an int, long, float, or |
498 |
|
* double field, or if <code>o</code> is not an instance of the |
499 |
|
* class declaring this field |
500 |
|
* @throws NullPointerException if <code>o</code> is null and this field |
501 |
|
* requires an instance |
502 |
|
* @throws ExceptionInInitializerError if accessing a static field triggered |
503 |
|
* class initialization, which then failed |
504 |
|
* @see #set(Object, Object) |
505 |
|
*/ |
506 |
|
public native void setInt(Object o, int value) |
507 |
|
throws IllegalAccessException; |
508 |
|
|
509 |
|
/** |
510 |
|
* Set this long Field. If the field is static, <code>o</code> will be |
511 |
|
* ignored. |
512 |
|
* |
513 |
|
* @param o the object to set this Field on |
514 |
|
* @param value the value to set this Field to |
515 |
|
* @throws IllegalAccessException if you could not normally access this field |
516 |
|
* (i.e. it is not public) |
517 |
|
* @throws IllegalArgumentException if this is not a long, float, or double |
518 |
|
* field, or if <code>o</code> is not an instance of the class |
519 |
|
* declaring this field |
520 |
|
* @throws NullPointerException if <code>o</code> is null and this field |
521 |
|
* requires an instance |
522 |
|
* @throws ExceptionInInitializerError if accessing a static field triggered |
523 |
|
* class initialization, which then failed |
524 |
|
* @see #set(Object, Object) |
525 |
|
*/ |
526 |
|
public native void setLong(Object o, long value) |
527 |
|
throws IllegalAccessException; |
528 |
|
|
529 |
|
/** |
530 |
|
* Set this float Field. If the field is static, <code>o</code> will be |
531 |
|
* ignored. |
532 |
|
* |
533 |
|
* @param o the object to set this Field on |
534 |
|
* @param value the value to set this Field to |
535 |
|
* @throws IllegalAccessException if you could not normally access this field |
536 |
|
* (i.e. it is not public) |
537 |
|
* @throws IllegalArgumentException if this is not a float or long field, or |
538 |
|
* if <code>o</code> is not an instance of the class declaring this |
539 |
|
* field |
540 |
|
* @throws NullPointerException if <code>o</code> is null and this field |
541 |
|
* requires an instance |
542 |
|
* @throws ExceptionInInitializerError if accessing a static field triggered |
543 |
|
* class initialization, which then failed |
544 |
|
* @see #set(Object, Object) |
545 |
|
*/ |
546 |
|
public native void setFloat(Object o, float value) |
547 |
|
throws IllegalAccessException; |
548 |
|
|
549 |
|
/** |
550 |
|
* Set this double Field. If the field is static, <code>o</code> will be |
551 |
|
* ignored. |
552 |
|
* |
553 |
|
* @param o the object to set this Field on |
554 |
|
* @param value the value to set this Field to |
555 |
|
* @throws IllegalAccessException if you could not normally access this field |
556 |
|
* (i.e. it is not public) |
557 |
|
* @throws IllegalArgumentException if this is not a double field, or if |
558 |
|
* <code>o</code> is not an instance of the class declaring this |
559 |
|
* field |
560 |
|
* @throws NullPointerException if <code>o</code> is null and this field |
561 |
|
* requires an instance |
562 |
|
* @throws ExceptionInInitializerError if accessing a static field triggered |
563 |
|
* class initialization, which then failed |
564 |
|
* @see #set(Object, Object) |
565 |
|
*/ |
566 |
|
public native void setDouble(Object o, double value) |
567 |
|
throws IllegalAccessException; |
568 |
} |
} |