The problem is that CF's Java support pre CFMX was real spotty. In some cases CF does indeed pass by reference, but only with complex objects. My advice to anyone trying to use Java objects with CF is try and do as much work as possible in Java then build a custom wrapper class that deals with CF's issues. Although, CFMX supports Java objects much much better, there are still some issues that force you to still use the above method.
-Matt > -----Original Message----- > From: Darren Houle [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, June 18, 2002 1:09 PM > To: CF-Talk > Subject: RE: CFOBJECT: Pass By Value vs. Pass By Reference > > Matt, > > Understood, and thanks! However, the WebContextor class, which I did not > originally write, contains a total of about 12 methods, not just run(). > Each method currently requires the blob be handled in the 'pass by > reference' manner, but two or three of those 12 methods are not void > methods and do return values. The original developer used this 'pass by > reference' ability to basically return more than one value at a time from > some of the methods. > > Because some methods do return a value your Wrapper suggestion probably > won't work for all the methods, only the ones that are void methods. > Since your Wrapper is already passing a Sting[] back it can't pass back > the other non-void data type. > > Do you know of any way other than > String[] SArray = new String[1] > to create a Java array? Even a Java Integer can be created as an > instanced class object intead of as a primitive. Or would that not help > me since I would then have to pass this new Array object into the > CFOBJECT's method, which would again 'copy' the value and not 'reference' > it?? Seems like it should pass by reference if it's anything more > complicated than the standard datatypes that CF recognizes and can > automatically convert. > > I mean, if I did the following: > > <cfobject action="create" type="java" class="java.net.ServerSocket" > name="mservsocket"> > <cfobject action="create" type="java" class="java.net.Socket" > name="msocket"> > <cfset mservsocket.implAccept(msocket)> > > Then CF wouldn't be able to convert the msocket into a string and pass a > copy, would it? Wouldn't it pass a reference to the Socket object into > the implAccept() method instead? > > I don't know if it would, or if you can use methods to create Java Array > objects, or if those Array objects would pass by reference or value, but > that's what I'm looking for a way to do. > > Thanks for your help Matt! > > Darren > > > > > > >>> [EMAIL PROTECTED] 06/18/02 03:00PM >>> > With CF 4.5 you can only pass data to Java objects by value. Either you > should change your run() method to return back the new value or if can't > do that, then you should create a wrapper class. Off the top of my > head... > > public class Wrapper > { > public String[] run(String blob[]) > { > WebContextor mcontextor = new WebContextor(); > mcontextor.run(blob); > return blob; > } > } > > -Matt > > > -----Original Message----- > > From: Darren Houle [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, June 18, 2002 11:23 AM > > To: CF-Talk > > Subject: CFOBJECT: Pass By Value vs. Pass By Reference > > > > Hello! New to this list - in the hopes that I can find some advice > for a > > tricky problem that I am facing: > > > > Problem: I need to use CFOBJECT to instantiate a Java class and then > run > > a few of its methods. The methods require an array be passed in as a > > parameter when called. > > > > Normally, in Java, you would do something like this: > > > > String[] blob = new String[1]; > > blob[0] = "original text"; > > WebContextor mcontextor = new WebContextor(); > > mcontextor.run(blob); > > out.println(blob); > > > > * Output would be "Some New Altered Text" > > > > As you can see, there is no return value for the run() method. Inside > the > > run() method the blob array is altered but it is not returned by the > > method, instead, the blob is somehow automatically 'passed by > reference' > > by Java into the method and the new altered value is now available to > the > > rest of the code in the main body upon return. > > > > When I use CFOBJECT to create the WebContextor class and call the > run() > > method, passing a CF array[], the values in the array are apparently > > 'passed by value' to the method. A copy is made of the array when it > is > > passed to run() so when I return from run() the original CF array has > not > > been altered and the new altered value is not available to the rest of > the > > CF code. > > > > <cfobject action="create" type="java" class="WebContextor" > > name="mcontextor"> > > <cfset blob = arrayNew(1)> > > <cfset blob[1]="original text"> > > <cfset mcontextor.run(blob)> > > <cfoutput>#blob[1]#</cfoutput> > > > > Output is "original text" - the contents of the array within this CF > page > > apparently has not been altered. > > > > I realize that there may be ways around this by creating and calling > > custom tags that, in turn, call the WebContextor, however, I would > like to > > know if anyone knows of a way to achieve this without using a custom > tag. > > I keep thinking that instead of passing a CF array to the run() method > I > > should first create a new Java Array CFOBJECT that can store the CF > array, > > and when the CFOBJECT WebContextor is instanced and it's run() method > > called, the Java Array can be passed instead of the CF array. Maybe > that > > will cause it to be passed by reference instead of by value? > > > > I am currently on CF Enterprise server 4.5 but have a new copy of MX > > Enterprise sitting on my desk. Don't know if anything along these > lines > > has changed in MX or if this is something I can already do in 4.5 but > any > > help at all would be tremendously appreciated !!!! > > > > Thanks, > > Darren Houle > > Sr. Web Developer > > Health First, Inc. > > > > > > "MMS <health-first.org>" made the following > > annotations on 06/18/02 14:39:22 > > > ------------------------------------------------------------------------ > -- > > ---- > > This message is for the named person's use only. It may contain > > confidential, proprietary, or legally privileged information. No > > confidentiality or privilege is waived or lost by any mistransmission. > If > > you receive this message in error, please immediately delete it and > all > > copies of it from your system, destroy any hard copies of it, and > notify > > the sender. You must not, directly or indirectly, use, disclose, > > distribute, print, or copy any part of this message if you are not the > > intended recipient. Health First reserves the right to monitor all > e-mail > > communications through its networks. Any views or opinions expressed > in > > this message are solely those of the individual sender, except (1) > where > > the message states such views or opinions are on behalf of a > particular > > entity; and (2) > > the sender is authorized by the entity to give such views or opinions. > > > > > ======================================================================== > == > > ==== > > > > > > ______________________________________________________________________ Your ad could be here. Monies from ads go to support these lists and provide more resources for the community. http://www.fusionauthority.com/ads.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

