Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Reference to an existing reference

  1. #1
    Junior Member
    Join Date
    Sep 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Reference to an existing reference

    In C/C++ I can easily address a pointer, as opposed to the memory/object it points to, by implying its address with the & operator. For example, I can store a pointer to an existing pointer as per follows:

    int integer1, integer2;
    int *pointer = &integer1;
    int **pointerToPointer = &pointer;
    *pointerToPointer = &integer2;

    Upon executing the above snippet, the value of "pointer" is directly modified by dereferencing the “pointerToPointer” address and ends up referencing integer2 as opposed to integer1.
    As the pointer-to-pointer or reference-to-reference semantic is extremely useful when dealing with all kinds of pointer-centric data structures, I was wondering whether or not Java has an analogous mechanism.

    I know I can change the value of a Java reference by explicitly assigning it an object address (e.g. reference = new object...), but is there any way I can store the address of the reference variable itself (not the address of the object it points to) for later use?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,381
    Thanks
    52
    Thanked 2,283 Times in 2,254 Posts

    Default Re: Reference to an existing reference

    is there any way I can store the address of the reference variable itself
    No
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reference to an existing reference

    Quote Originally Posted by Norm View Post
    No
    Cheers, just as I thought.

Similar Threads

  1. Can't pass by reference?
    By JavaDeveloperPeter in forum What's Wrong With My Code?
    Replies: 31
    Last Post: August 25th, 2014, 12:53 PM
  2. Reference type
    By gunitinug in forum Object Oriented Programming
    Replies: 2
    Last Post: March 21st, 2014, 09:52 AM
  3. Get Reference of js files
    By Priyankati in forum Other Programming Languages
    Replies: 1
    Last Post: February 11th, 2013, 11:04 AM
  4. Value vs Reference Types
    By anis.laghaei in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 23rd, 2012, 12:21 PM
  5. Object Reference
    By Mr.777 in forum Object Oriented Programming
    Replies: 2
    Last Post: June 13th, 2011, 03:03 AM

Tags for this Thread