Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 38562 invoked from network); 15 Nov 2007 06:31:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Nov 2007 06:31:51 -0000 Received: (qmail 91462 invoked by uid 500); 15 Nov 2007 06:31:37 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 91437 invoked by uid 500); 15 Nov 2007 06:31:37 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 91428 invoked by uid 99); 15 Nov 2007 06:31:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Nov 2007 22:31:37 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of firepure@gmail.com designates 64.233.166.182 as permitted sender) Received: from [64.233.166.182] (HELO py-out-1112.google.com) (64.233.166.182) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Nov 2007 06:31:27 +0000 Received: by py-out-1112.google.com with SMTP id u77so3412556pyb for ; Wed, 14 Nov 2007 22:31:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=ARbw/vGDwGblDCK9PsuvJ5b8+/i1Vrmy4uIxifAZR/A=; b=NGgoua+Ln2Joh010iy2eQyiG1dpg2o2iP6R1e7OClHOsX86vKQefz5JFV206/x1uZ2wRX3+St9qk+Cx+LEktf0XvlQ9nVQNK8pvPKl1+PHstR+X++HP48qSo8quTqEGNxq4rMWTwgA9L7LQY6hzFnEy59w5bi5RtsbUuPQdoEW0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=En7nuY5bRTr/20d1yk3EMzWoOiDhPV5RSEGL+RKIhCqQwffRcY6KCU/puRiPO827KwTMzxNZ7KxCyYCMSmla50jVK9L8msjjSVC4xGIk+1DcqDNuDh2C1Ow+EjKePxVwXFCNepZqxVOcx+kwiSZ4ATBNhMPtNusCnk++/yW6r0k= Received: by 10.64.241.3 with SMTP id o3mr765454qbh.1195108280327; Wed, 14 Nov 2007 22:31:20 -0800 (PST) Received: by 10.65.157.19 with HTTP; Wed, 14 Nov 2007 22:31:20 -0800 (PST) Message-ID: <5c8e69f0711142231r517dc51eq6f3126f5ebb22132@mail.gmail.com> Date: Thu, 15 Nov 2007 14:31:20 +0800 From: "Jimmy,Jing Lv" To: dev@harmony.apache.org Subject: Re: [classlib][lang] Is it possible to new an object without invoking any constructor? In-Reply-To: <4d0b24970711142153n12186455kf7a6da88997f2684@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4d0b24970711142058k7604eacfxf63ec105acf00583@mail.gmail.com> <5c8e69f0711142122x18f0f476r740b4098f2e5fd7a@mail.gmail.com> <4d0b24970711142153n12186455kf7a6da88997f2684@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org 2007/11/15, Andrew Zhang : > On Nov 15, 2007 1:22 PM, Jimmy,Jing Lv 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) . 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, "", "()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 : > > > 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