pointer/reference kinda thing


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: pointer/reference kinda thing

  1. #1
    Join Date
    Feb 2003
    Posts
    5

    pointer/reference kinda thing

    An example of what i'm looking to do is:

    swap(x, y);

    and the swap method should be able to work with the values of the variables directly instead of working with copies.

  2. #2
    Join Date
    Nov 2002
    Posts
    59
    Then just make a method to do it...I won't do it for you, but here's a hint: You need 3 variables to swap 2

  3. #3
    Join Date
    Feb 2003
    Posts
    5
    The swap was an example. Here's the main point that you seem to have missed.
    work with the values of the variables directly instead of working with copies
    For example (pseudo code),
    Code:
    swap(a, b);
    
    swap(x, y) {
        ...
        // modifying x and y here will do nothing to a and b
    }

  4. #4
    Join Date
    Nov 2002
    Posts
    59
    Ah...the problem then is that you're sending the variable rather than an object...Java's kinda strange like that.

    Quite possibly the easiest way is to make a whole class that does the swap then reassign the values after that method gets done

    Another way would be to wrap them as objects...like Integer(a) then send them...but you have to change them to regular int's to work with them then change it back and reassign them...but if you use the class enough it would be worth it. to figure out all of the changing stuff, check the java api.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center