Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: JNI return jobjectArray Date: Sun, 30 Sep 2012 14:56:57 -0700 Organization: A noiseless patient Spider Lines: 46 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 30 Sep 2012 21:57:00 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="61282af8d6595e8d991edb5ac03d6e00"; logging-data="30136"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/APALjpvPbdjZx8E3OowGkg8yjLaROgI=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: Cancel-Lock: sha1:44qp7x6rX+iEbw8i/UNPSf9WNG4= Xref: csiph.com comp.lang.java.programmer:19000 On 9/30/2012 1:23 PM, Philipp Kraus wrote: > Hello, > > I hope this question is not OT. > > I create a JNI call for this Java method > > class myclass { > > void native mymethod( Double[] x ) > } > > so the parameter x should be a call-by-reference, I would set x in the > native JNI function: > > void mymethod( JNIEnv *jenv, jclass jcls, jobjectArray& jarg ) > { > // do something > jobjectArray t = ..... > > jarg = t; > } > > How can I set the jobjectArray& back, so the data is return in the > parameter x? You can't. Java doesn't have a pass-by-reference call scheme, at all. Java uses only pass by value. You could: 1. Return the new array as a return value. 2. Create a reference to a reference so you can replace the 2nd one: > class myclass { > > void native mymethod( Double[][] x ) > } will give you a pointer to an array which you can then modify. A Google search for "Java pass by reference" will give you lots of details. Maybe add "jni" to get some clues more specific results for your particular situation.