-
1. Re: TypeInfo.newArrayInstance problems
adrian.brock Oct 12, 2007 10:52 AM (in response to alesj)char is not an object.
To satisfy the cast to Object[] you'll need to "autobox" it to Character[] -
2. Re: TypeInfo.newArrayInstance problems
adrian.brock Oct 12, 2007 10:55 AM (in response to alesj)Or perhaps we should have a version like the reflect api
that returns an Object instead of Object[]?
char[] is an Object even if it isn't an Object[]
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Array.html#newInstance(java.lang.Class,%20int) -
3. Re: TypeInfo.newArrayInstance problems
alesj Oct 12, 2007 11:00 AM (in response to alesj)"adrian@jboss.org" wrote:
char[] is an Object even if it isn't an Object[]
Yup, thought of that. ;-)
But this sucks, since then you don't know what to do when you have something like this:Object[] array; try { array = type.newArrayInstance(arrayValue.getLength()); } catch (Throwable t) { throw new UndeclaredThrowableException(t); } for (int j = 0; j < array.length; j++) { Object element = arrayValue.getValue(i); if (element instanceof MetaValue) { TypeInfo elementType = configuration.getTypeInfo(element.getClass()); element = unwrap((MetaValue)element, elementType); } array[j] = element; }
How to assign element to array if it were plain Object? :-) -
4. Re: TypeInfo.newArrayInstance problems
alesj Oct 12, 2007 11:04 AM (in response to alesj)Hmmm ... I was able to 'autobox' it.
Method is expecting char[] and I pushed in Character[], which is still not good.
I guess having plain Object is what we need ... -
5. Re: TypeInfo.newArrayInstance problems
adrian.brock Oct 12, 2007 11:11 AM (in response to alesj)For the plain Object you'd need to change your code to use something like the reflect api:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Array.html#getLength(java.lang.Object)
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Array.html#get(java.lang.Object,%20int)
The latter method automatically autoboxes the primitives.import java.lang.reflect.Array; ... Object array; try { array = type.newArrayInstanceObject(arrayValue.getLength()); } catch (Throwable t) { throw new UndeclaredThrowableException(t); } for (int j = 0; j < Array.getLength(array); j++) { Object element = arrayValue.getValue(i); if (element instanceof MetaValue) { TypeInfo elementType = configuration.getTypeInfo(element.getClass()); element = unwrap((MetaValue)element, elementType); } Array.set(array, j, element); }
-
6. Re: TypeInfo.newArrayInstance problems
alesj Oct 12, 2007 11:35 AM (in response to alesj)"adrian@jboss.org" wrote:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Array.html#getLength(java.lang.Object)
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Array.html#get(java.lang.Object,%20int)
The latter method automatically autoboxes the primitives.
Yup, was aware of this methods. :-)
Only questioned if we should 'hide' them in TypeInfo - only applicable for TypeInfo.isArray == true?
Or just ArrayInfo? -
7. Re: TypeInfo.newArrayInstance problems
adrian.brock Oct 12, 2007 11:43 AM (in response to alesj)"alesj" wrote:
"adrian@jboss.org" wrote:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Array.html#getLength(java.lang.Object)
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Array.html#get(java.lang.Object,%20int)
The latter method automatically autoboxes the primitives.
Yup, was aware of this methods. :-)
Only questioned if we should 'hide' them in TypeInfo - only applicable for TypeInfo.isArray == true?
Or just ArrayInfo?
Why? I don't think this is something that javassist could optimize is it?
It's not like a Method or Field invocation
where you generate one class for each method you invoke. -
8. Re: TypeInfo.newArrayInstance problems
alesj Oct 12, 2007 11:49 AM (in response to alesj)"adrian@jboss.org" wrote:
Why? I don't think this is something that javassist could optimize is it?
It's not like a Method or Field invocation
where you generate one class for each method you invoke.
Understood and agreed. :-)
And the good thing is that the usage of this method is minimal - 1 existing case + my new one. -
9. Re: TypeInfo.newArrayInstance problems
alesj Oct 12, 2007 11:52 AM (in response to alesj)"alesj" wrote:
And the good thing is that the usage of this method is minimal - 1 existing case + my new one.
The tests disagree.
More then one failing. :-)
I'll try to fix them. -
10. Re: TypeInfo.newArrayInstance problems
alesj Oct 12, 2007 12:31 PM (in response to alesj)Got them all running.
Commiting the changes. :-)