pointers in java

Discussion in 'Java' started by New, May 11, 2004.

  1. New

    New Guest

    Is it possible to have pointer in java (like C) so that an object can point
    to another object it can point back to it without have the whole other
    object inside the object because it becames an infinite loop?

    Thank you
     
    New, May 11, 2004
    #1
    1. Advertising

  2. New wrote:

    > Is it possible to have pointer in java (like C) so that an object can
    > point to another object it can point back to it without have the whole
    > other object inside the object because it becames an infinite loop?
    >
    > Thank you


    Hmm, lots of confusion here.

    First of all, Java doesn't have pointers, but references. You can do less
    with references than with pointers.

    I'm guessing that you're asking about wether it's ok to have a circular
    references, as in

    A has a references to B, which has a reference to A.

    This will work without a problem, an will allow both A and B to get garbage
    collected, provided you have no other references to A or B.

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, May 11, 2004
    #2
    1. Advertising

  3. On Tue, 11 May 2004 20:00:10 +1000, New wrote:

    > Is it possible to have pointer in java (like C) so that an object can point
    > to another object it can point back to it without have the whole other
    > object inside the object because it becames an infinite loop?


    Yes, Java's references match pointers pretty closely in this respect.
     
    Timo Kinnunen, May 11, 2004
    #3
  4. New

    Roedy Green Guest

    On Tue, 11 May 2004 20:00:10 +1000, "New" <> wrote or quoted :

    >Is it possible to have pointer in java (like C) so that an object can point
    >to another object it can point back to it without have the whole other
    >object inside the object because it becames an infinite loop?


    yes anything can point to anything in loops. An object can point to
    itself.

    This causes no problem unless you CHASE the chains endlessly.

    see http://mindprod.com/jgloss/reference.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, May 11, 2004
    #4
  5. "Christophe Vanfleteren" <> wrote in message
    news:EC1oc.102524$-ops.be...
    > New wrote:
    >
    > > Is it possible to have pointer in java (like C) so that an object can
    > > point to another object it can point back to it without have the whole
    > > other object inside the object because it becames an infinite loop?
    > >
    > > Thank you

    >
    > Hmm, lots of confusion here.
    >
    > First of all, Java doesn't have pointers, but references. You can do less
    > with references than with pointers.


    That is, Java calls its pointers "references", probably because C and C++
    are so familiar these days that calling them "pointers" would imply that
    they supported C-like pointer arithmetic. In an alternate would in which
    Pascal had the sort of success that C has had, the word "pointers" would
    describe Java references quite well.
     
    Mike Schilling, May 11, 2004
    #5
  6. New

    Tony Morris Guest

    > This will work without a problem, an will allow both A and B to get
    garbage
    > collected, provided you have no other references to A or B.


    This is not guaranteed i.e. implementation specific behaviour.

    --
    Tony Morris
    (BInfTech, Cert 3 I.T.)
    Software Engineer
    (2003 VTR1000F)
    Sun Certified Programmer for the Java 2 Platform (1.4)
    Sun Certified Developer for the Java 2 Platform
     
    Tony Morris, May 12, 2004
    #6
  7. New

    Andrew Hobbs Guest

    "Tony Morris" <> wrote in message
    news:c7rn4t$ddg$...
    > > This will work without a problem, an will allow both A and B to get

    > garbage
    > > collected, provided you have no other references to A or B.

    >
    > This is not guaranteed i.e. implementation specific behaviour.


    Can you explain what you mean here. Surely simple circular references, A to
    B and B to A, will not affect anything unless some method(s) creates a
    circular execution path.

    And if there are no references then they should be eligible for GC.

    Andrew

    >
    > --
    > Tony Morris
    > (BInfTech, Cert 3 I.T.)
    > Software Engineer
    > (2003 VTR1000F)
    > Sun Certified Programmer for the Java 2 Platform (1.4)
    > Sun Certified Developer for the Java 2 Platform
    >
    >
    >
     
    Andrew Hobbs, May 12, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil
    Replies:
    1
    Views:
    670
    llewelly
    Sep 16, 2003
  2. muser
    Replies:
    3
    Views:
    783
    Ron Natalie
    Sep 18, 2003
  3. A
    Replies:
    3
    Views:
    478
    Alan Kelon
    Oct 29, 2003
  4. Xamalek
    Replies:
    7
    Views:
    708
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    731
Loading...

Share This Page