Jump to content
  • Advertisement
Sign in to follow this  

[java] Quick and Easy Question

This topic is 3890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can't seem to get this to stick in my head but: if I create a graphics object ("myGraphics") and then create another Graphics Object ("myOtherGraphics") and set myOtherGraphics = myGraphics.getGraphics(); then, when I make changes to myGraphics, do the same changes happen to myOtherGraphics? or the other way around? in other words, are they referencing the same object. and if not, even though they aren't referencing the same object, does making changes to one, change the other? sorry if this is bit elementary. :)

Share this post

Link to post
Share on other sites

Graphics myGraphics = new Graphics();
Graphics myOtherGraphics = new Graphics();

myGraphics ---------------> Instance #1

myOtherGraphics ----------> Instance #2

myOtherGraphics = myGraphics;

myGraphics --------+------> Instance #1
myOtherGraphics ---+ Instance #2

// Instance #2 is garbage collected, since nothing is pointing at it anymore

in other words, are they referencing the same object


myOtherGraphics = myGraphics.getGraphics();

Why myGraphics.getGraphics()? Why not myOtherGraphics = myGraphics; ?

getGraphics() could be returning anything, in which case what they point to depends on how getGraphics is implemented.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!