On Nov 15, 2007 3:37 PM, Andrew Zhang <[EMAIL PROTECTED]> wrote:
>
>
> On Nov 15, 2007 2:46 PM, Andrew Zhang <[EMAIL PROTECTED]> wrote:
>
> >
> >
> > On Nov 15, 2007 2:31 PM, Jimmy,Jing Lv <[EMAIL PROTECTED]> wrote:
> >
> > > 2007/11/15, Andrew Zhang <[EMAIL PROTECTED]>:
> > > > On Nov 15, 2007 1:22 PM, Jimmy,Jing Lv < [EMAIL PROTECTED]> wrote:
> > > >
> > > > > A simple thought is using the JNI call AllocObject(JNIEnv *env,
> > > jclass
> > > > > clazz);
> > > > > however we need to implement a native api then :)
> > > > >
> > > >
> > > > Thanks Jimmy!
> > > >
> > >
> > > :)
> > >
> > > > AllocObject looks like what I want. ObjectInputStream#newInstance is
> > > even
> > > > closer (it has defined a native method). Is it possible to refactor?
> > > > Comments? Thanks!
> > > >
> > >
> > > Hmm, it seems the current native method newInstance is used for
> > > ObjectInputStream itself, so refactor it may not be a good idea (will
> > > surely break Harmony function) .
> >
> >
> > No, I mean add a similar method in the ObjectInputStream, e.g private
> > static native allocObject(Class <?> c);
> >
> > Or put it in some util class in o.a.h package. Any comments or
> > objections?
> >
>
> Found it! It's already in misc module.
>
>
> working_classlib\modules\misc\src\main\java\org\apache\harmony\misc\accessors\ObjectAccessor.java
>
> public final native Object allocateObject(Class c);
>
Hi,
Can we make ObjectAccessor.getInstance() public? It's package friend now...
>
>
> >
> > I suggest define it in some utility
> > > class or your own class :)
> > >
> > > > Java_java_io_ObjectInputStream_newInstance (JNIEnv * env, jclass
> > > clazz,
> > > > jobject
> > > instantiationClass,
> > > > jobject
> > > constructorClass)
> > > > {
> > > > jmethodID mid =
> > > > (*env)->GetMethodID (env, constructorClass, "<init>", "()V");
> > > >
> > > > if (mid == 0)
> > > > {
> > > > /* Cant newInstance,No empty constructor... */
> > > > return (jobject) 0;
> > > > }
> > > > else
> > > > {
> > > > /* Instantiate an object of a given class and constuct it
> > > using
> > > > the constructor of the other class. */
> > > > jobject obj;
> > > > obj = (*env)->AllocObject(env, instantiationClass); // I want
> > > this
> > > > method :)
> > > > if (obj != NULL) {
> > > > (*env)->CallNonvirtualVoidMethod(env, obj, constructorClass,
> > > mid);
> > > > }
> > > > return obj;
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > > > 2007/11/15, Andrew Zhang < [EMAIL PROTECTED]>:
> > > > > > Hi,
> > > > > >
> > > > > > Is it possible to new an object without invoking any
> > > constructor? I know
> > > > > the
> > > > > > question is a bit weird. What I want is to create an object with
> > > all
> > > > > > null/default value for its fields.
> > > > > > Reseting all fields to null by reflection is a possible
> > > solution, but is
> > > > > > there any existing special method (no matter it's low level or
> > > Harmony
> > > > > > specific) which can achieve this goal?
> > > > > > Thanks!
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Best regards,
> > > > > > Andrew Zhang
> > > > > >
> > > > > > http://zhanghuangzhu.blogspot.com/
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Best Regards!
> > > > >
> > > > > Jimmy, Jing Lv
> > > > > China Software Development Lab, IBM
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Best regards,
> > > > Andrew Zhang
> > > >
> > > > http://zhanghuangzhu.blogspot.com/
> > > >
> > >
> > >
> > > --
> > >
> > > Best Regards!
> > >
> > > Jimmy, Jing Lv
> > > China Software Development Lab, IBM
> > >
> >
> >
> >
> > --
> >
> > Best regards,
> > Andrew Zhang
> >
> > http://zhanghuangzhu.blogspot.com/
> >
>
>
>
> --
>
> Best regards,
> Andrew Zhang
>
> http://zhanghuangzhu.blogspot.com/
>
--
Best regards,
Andrew Zhang
http://zhanghuangzhu.blogspot.com/