News:

Facebook killed the radio star. And by radio star, I mean the premise of distributed forums around the internet. And that got got by Instagram/SnapChat. And that got got by TikTok. Where the fuck is the internet we once knew?

Main Menu

Integer by reference..

Started by Joe, February 07, 2007, 03:13:26 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Joe

Is there any easy way to pass an int or Integer by reference in Java? I want to but it won't let me. :(
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


d&q

Use an int array with one value? That's probably not the best method though..
The writ of the founders must endure.

Chavo

passing be reference/value isn't as black & white in java as it is in other languages, what are you trying to do?

Joe

filename, formula, and filetime should be byvalue and checksum, verhas, and exeinfo should be byreference.

exeinfo is already byreference, but my attempt to pass checksum and verhash as an object (Integer opposed to int) failed.

public void getVersionCheck(String filename, String formula, long filetime, Integer checksum, Integer verhash, String exeinfo) throws IOException
    {
        Socket s = getConnection();
        BufferedReader in = getReader(s);
        BufferedWriter out = getWriter(s);
       
BNLSPacket pkt = new BNLSPacket(BNLS_VERSIONCHECKEX2);
pkt.addDWord(getBnlsProductId(game)); // (DWORD) Product ID
pkt.addDWord(0); // (DWORD) Flags**
pkt.addDWord(0); // (DWORD) Cookie
pkt.addLong(filetime); // (ULONGLONG) Timestamp for version check archive
pkt.addNTString(filename); // (STRING) Version check archive filename.
pkt.addNTString(formula); // (STRING) Checksum formula.
out.write(pkt.getChars());
out.flush();

BNLSPacket inPkt = getNextPacket(in);
/*(BOOL) Success*
(DWORD) Version.
(DWORD) Checksum.
(STRING) Version check stat string.
(DWORD) Cookie.
(DWORD) The latest version code for this product.*/
inPkt.removeDWord();
verhash = inPkt.removeDWord();
checksum = inPkt.removeDWord();
exeinfo = inPkt.removeNTString();
   
    }
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Sidoh

Here's a good article on this subject, Joe.  In short, I think you're going to have to find a different way to solve this problem.  You could invent a convoluted way to implement a "by reference" method (like deuce suggested, the only thing I can think of offhand is to have an object or an array of some sort), but I think you can come up with something better.

Chavo

You could encapsulate all your parameters in an object and then just pass references to that object.

Sidoh

Quote from: unTactical on February 07, 2007, 05:06:52 PM
You could encapsulate all your parameters in an object and then just pass references to that object.

I recommended that, but in a less elaborate way. :(

Like I said though, I don't think there's any non-convoluted way to do what you're wanting to do.

Chavo

encapsulation isn't a convoluted unless you do it in an ugly way like a one element array!

d&q

Quote from: unTactical on February 07, 2007, 05:42:05 PM
encapsulation isn't a convoluted unless you do it in an ugly way like a one element array!

:(
The writ of the founders must endure.

Chavo

lol, that wasn't a shot at you deuce, its just an ugly way

Warrior

put all your vars in a object then pass that by ref.

im a genius.
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

rabbit

Make a class that consists entirely of the value types you want to get back, and return that from the function.  That is what Java is made for.

MyndFyre

Quote from: rabbit on February 07, 2007, 08:04:05 PM
Make a class that consists entirely of the value types you want to get back, and return that from the function.  That is what Java is made for.

Heh.  I was thinking that myself.  I'm pretty sure that's what Sidoh was thinking, too.  And Warrior.  And unTactical.  ;)
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

rabbit

It's what anyone who's gotten past chapter 2 of "Java for Dummies" should think.

Sidoh

Quote from: unTactical on February 07, 2007, 05:42:05 PM
encapsulation isn't a convoluted unless you do it in an ugly way like a one element array!

Haha, it is for some situations.

Quote from: rabbit on February 07, 2007, 11:14:19 PM
It's what anyone who's gotten past chapter 2 of "Java for Dummies" should think.

You bug me.