📄 field.java
字号:
/* libaegisvm - The Aegis Virtual Machine for executing Java bytecode Copyright (C) 2001-2002 Philip W. L. Fong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/package java.lang.reflect;public final class Field extends AccessibleObject implements Member { private Class declaringClass; // The VM depends on the object private int id; // layout of the class. private Field(Class declaringClass, int id) { this.declaringClass = declaringClass; this.id = id; } public Class getDeclaringClass() { return declaringClass; } public native String getName(); private native String getDescriptor(); public native int getModifiers(); public Class getType() { return aegis.Reflect.getFieldType(declaringClass, getDescriptor()); } public boolean equals(Object obj) { if (! (obj instanceof Field)) return false; Field F = (Field) obj; return declaringClass == F.declaringClass && id == F.id; } public int hashCode() { return getDeclaringClass().hashCode() ^ getName().hashCode(); } public String toString() { return Modifier.toString(getModifiers()) + getType().getName() + ' ' + declaringClass.getName() + '.' + getName(); } private static native Object get(Class declaringClass, int id, Object obj); /** * \todo Accessibility check. */ public Object get(Object obj) throws IllegalArgumentException, IllegalAccessException { if (! Modifier.isStatic(getModifiers())) { if (obj == null) throw new NullPointerException(); if (! declaringClass.isInstance(obj)) throw new IllegalArgumentException(); } // Accessibility check goes here return get(declaringClass, id, obj); } public boolean getBoolean(Object obj) throws IllegalArgumentException, IllegalAccessException { return aegis.Reflect.widenToBoolean(getType(), get(obj)); } public byte getByte(Object obj) throws IllegalArgumentException, IllegalAccessException { return aegis.Reflect.widenToByte(getType(), get(obj)); } public char getChar(Object obj) throws IllegalArgumentException, IllegalAccessException { return aegis.Reflect.widenToCharacter(getType(), get(obj)); } public short getShort(Object obj) throws IllegalArgumentException, IllegalAccessException { return aegis.Reflect.widenToShort(getType(), get(obj)); } public int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException { return aegis.Reflect.widenToInteger(getType(), get(obj)); } public long getLong(Object obj) throws IllegalArgumentException, IllegalAccessException { return aegis.Reflect.widenToLong(getType(), get(obj)); } public float getFloat(Object obj) throws IllegalArgumentException, IllegalAccessException { return aegis.Reflect.widenToFloat(getType(), get(obj)); } public double getDouble(Object obj) throws IllegalArgumentException, IllegalAccessException { return aegis.Reflect.widenToDouble(getType(), get(obj)); } private static native void set(Class clazz, int id, Object obj, Object value); /** * \todo Accessibility check. */ public void set(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException { if (! Modifier.isStatic(getModifiers())) { if (obj == null) throw new NullPointerException(); if (! declaringClass.isInstance(obj)) throw new IllegalArgumentException(); } // Accessibility check goes here if (Modifier.isFinal(getModifiers())) throw new IllegalAccessException(); value = aegis.Reflect.widen(value, getType()); set(declaringClass, id, obj, value); } public void setBoolean(Object obj, boolean z) throws IllegalArgumentException, IllegalAccessException { set(obj, new Boolean(z)); } public void setByte(Object obj, byte b) throws IllegalArgumentException, IllegalAccessException { set(obj, new Byte(b)); } public void setChar(Object obj, char c) throws IllegalArgumentException, IllegalAccessException { set(obj, new Character(c)); } public void setShort(Object obj, short s) throws IllegalArgumentException, IllegalAccessException { set(obj, new Short(s)); } public void setInt(Object obj, int i) throws IllegalArgumentException, IllegalAccessException { set(obj, new Integer(i)); } public void setLong(Object obj, long l) throws IllegalArgumentException, IllegalAccessException { set(obj, new Long(l)); } public void setFloat(Object obj, float f) throws IllegalArgumentException, IllegalAccessException { set(obj, new Float(f)); } public void setDouble(Object obj, double d) throws IllegalArgumentException, IllegalAccessException { set(obj, new Double(d)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -