Author Topic: Integer by reference..  (Read 9372 times)

0 Members and 1 Guest are viewing this topic.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Integer by reference..
« on: February 07, 2007, 03:13:26 am »
Is there any easy way to pass an int or Integer by reference in Java? I want to but it won't let me. :(
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline d&q

  • Hero Member
  • *****
  • Posts: 1427
  • I'm here.
    • View Profile
    • Site
Re: Integer by reference..
« Reply #1 on: February 07, 2007, 05:17:01 am »
Use an int array with one value? That's probably not the best method though..
The writ of the founders must endure.

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: Integer by reference..
« Reply #2 on: February 07, 2007, 10:20:21 am »
passing be reference/value isn't as black & white in java as it is in other languages, what are you trying to do?

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Integer by reference..
« Reply #3 on: February 07, 2007, 03:32:39 pm »
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.

Code: [Select]
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();
   
    }
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Integer by reference..
« Reply #4 on: February 07, 2007, 04:22:57 pm »
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.

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: Integer by reference..
« Reply #5 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.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Integer by reference..
« Reply #6 on: February 07, 2007, 05:09:58 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.

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: Integer by reference..
« Reply #7 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!

Offline d&q

  • Hero Member
  • *****
  • Posts: 1427
  • I'm here.
    • View Profile
    • Site
Re: Integer by reference..
« Reply #8 on: February 07, 2007, 06:26:19 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.

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: Integer by reference..
« Reply #9 on: February 07, 2007, 06:56:05 pm »
lol, that wasn't a shot at you deuce, its just an ugly way

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: Integer by reference..
« Reply #10 on: February 07, 2007, 07:27:15 pm »
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

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: Integer by reference..
« Reply #11 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.

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Integer by reference..
« Reply #12 on: February 07, 2007, 10:16:26 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.  ;)
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: Integer by reference..
« Reply #13 on: February 07, 2007, 11:14:19 pm »
It's what anyone who's gotten past chapter 2 of "Java for Dummies" should think.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Integer by reference..
« Reply #14 on: February 08, 2007, 02:53:21 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.

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

You bug me.