• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return this

 
Kendall Ponder
Ranch Hand
Posts: 205
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does var and varNew now point to the same object in the code below? I think they do but I wanted to confirm. Thanks!
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kendall Ponder wrote:Does var and varNew now point to the same object in the code below? I think they do but I wanted to confirm.

I'm pretty sure you can answer your own question here. Think of 1 statement you could add which will verify (or not) that both reference variables refer to the same object. Give it a try!
 
Tim Cooke
Sheriff
Pie
Posts: 3203
142
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object equality is tested using the '==' operator. Given this, can you now add line to your code that will tell you if the two references point to the same object, or not?
 
Kendall Ponder
Ranch Hand
Posts: 205
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prints true so they do refer to the same object. Thanks!
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kendall Ponder wrote:Does var and varNew now point to the same object in the code below? I think they do but I wanted to confirm. Thanks!


A way of doing it with out testing is thinking in line 6 var now refers to a particular object.
In line 7 getClass1() which returns this is being called on that same var, so this means the object that var refers to.
So in 7, that this is being assigned to newVar, so of course they are ==

Because unfortunately you can't test during the test...

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kendall Ponder wrote:
Prints true so they do refer to the same object.

That was indeed the correct statement!

And what's the result of this code snippet?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic