Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 45866 invoked from network); 15 Nov 2007 07:16:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Nov 2007 07:16:47 -0000 Received: (qmail 23438 invoked by uid 500); 15 Nov 2007 07:16:33 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 23417 invoked by uid 500); 15 Nov 2007 07:16:33 -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 23402 invoked by uid 99); 15 Nov 2007 07:16:33 -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 23:16:33 -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 alexey.v.varlamov@gmail.com designates 209.85.132.251 as permitted sender) Received: from [209.85.132.251] (HELO an-out-0708.google.com) (209.85.132.251) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Nov 2007 07:16:22 +0000 Received: by an-out-0708.google.com with SMTP id b8so100172ana for ; Wed, 14 Nov 2007 23:16:12 -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=DDxthg2rBkPjMqE1LlBt1mJw2d3GIpkv5AMsTG2e5TQ=; b=iAchyyksb6UUbqu3Z4v4ps+tjJCWO+x+9dkUH8Kk4hQGOZTgDrnbLiqfGYuHJdRhyS+UY1FUFqlhMO4OjDKBJAJNlsWExsc/3VV2eNYOz6Mt55zDDB48XL4SrRo+JQI0MZ/XwqMFa6mVBAq6QVuF7+j3xqiPBe4W8RJAqzPspPw= 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=bYdoBRzjXfumd6m3NvR0/tq5SRZreDoZrAqU/n/CcjVLSiTNaNJqNGgzDsm7DT2EydiDDD8EYhfzC6BVdYi0OMKa8BVg2vxnon1f0bxYtBljX6VUvwnQUx5ywWAkgV3PF8xYRiLAZkNDEWaKJBg04CJZgxwJSoKO/uvV0KPJrYs= Received: by 10.142.103.6 with SMTP id a6mr37098wfc.1195110972134; Wed, 14 Nov 2007 23:16:12 -0800 (PST) Received: by 10.143.5.6 with HTTP; Wed, 14 Nov 2007 23:16:11 -0800 (PST) Message-ID: Date: Thu, 15 Nov 2007 13:16:11 +0600 From: "Alexey Varlamov" To: dev@harmony.apache.org Subject: Re: [classlib][lang] Is it possible to new an object without invoking any constructor? In-Reply-To: <4d0b24970711142246y6ab7b8a1m5c1c7e5892c50154@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> <5c8e69f0711142231r517dc51eq6f3126f5ebb22132@mail.gmail.com> <4d0b24970711142246y6ab7b8a1m5c1c7e5892c50154@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org 2007/11/15, Andrew Zhang : > On Nov 15, 2007 2:31 PM, Jimmy,Jing Lv wrote: > > > 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) . > > > 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? But why do you need this in Harmony? > > 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 > > > > > > -- > Best regards, > Andrew Zhang > > http://zhanghuangzhu.blogspot.com/ >