I noticed that Java Reflection supports access on fields of primitive types such as boolean or int without boxing:
public final class Field extends AccessibleObject implements Member {
//...
public boolean getBoolean(Object obj) throws IllegalArgumentException, IllegalAccessException { ... }
public char getChar(Object obj) throws IllegalArgumentException, IllegalAccessException { ... }
public byte getByte(Object obj) throws IllegalArgumentException, IllegalAccessException { ... }
public short getShort(Object obj) throws IllegalArgumentException, IllegalAccessException { ... }
public int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException { ... }
public long getLong(Object obj) throws IllegalArgumentException, IllegalAccessException { ... }
public float getFloat(Object obj) throws IllegalArgumentException, IllegalAccessException { ... }
public double getDouble(Object obj) throws IllegalArgumentException, IllegalAccessException { ... }
//...
}
However, there is only invoke(...) for methods which always returns Object. This forces boxing when it is used with methods with primitive return values. I wonder why there is no support for that yet. Has it not been asked for or are there serious issues which prevent it?
Aucun commentaire:
Enregistrer un commentaire