<tangent>

You can get primitive types dynamically from a Field by first taking a look at what Field getType().getName() returns and, if it's a primitive, calling the appropriate Field getXXX() method. For example, if f[i].getType().getName() returns "int" (as opposed to, say, "java.lang.Integer") you can call f[i].getInt() to get the int directly (rather than pulling the int out of an Integer later by calling the Integer intValue() method).

</tangent>

@D


At 04:21 PM 1/23/2003 +1100, Scot Mcphee wrote:
> Thanks, didn't know about TYPE either...  My interest was that a Class
> actually exists to describe a native type int, even though native
> types are
> not Classes per se and can't be instantiated... (e.g., obviously, int i =
> new int(2); fails and actually thinks an int[] is attempting to be created
> from the error message).
>

If you look at reflection also the Type of a field which is a primitive is
also Integer, Double, Boolean, Char, etc. For example;

Field[] f = someInstance.getClass().getFields();
for (int i = 0; i < f.length; i++) {
        Object o = f[i].get(someInstance);
        /* do something here */
}

if 'someInstance' has fields int, char, boolean etc the Object that
Field.get(Object instance) will return is the wrapper class of the
primitive.

regs
scot.


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
David Gallardo | Software consultant | Author
Java, C/C++ software development | Database development | Internationalization
Author of "Java Oracle Database Development"


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to