• Post Reply Bookmark Topic Watch Topic
  • New Topic

want to know the benefit of using reference variable like Emp e2=e1  RSS feed

 
Neeraj Goyal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem is that i have used Emp e2=e1; e1 and e2 are the reference variables. and just passing e1 into e2 and accesing the functions by e2 reference variable. Just want to know what is the benefit of accesing by using Emp e2=e1.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

In future, please CarefullyChooseOneForum I have moved your posts from the JNLP forum because they are not related to JNLP.
I have also closed the other post, which was almost similar to this one.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neeraj Goyal wrote:problem is that i have used Emp e2=e1; e1 and e2 are the reference variables. and just passing e1 into e2 and accesing the functions by e2 reference variable. Just want to know what is the benefit of accesing by using Emp e2=e1.


All by itself, that's pointless. But maybe you have a situation like this:



In this case, we want to do something with a particular Emp object, but we have to pick which one based on some condition. So we use a separate variable for a copy of the reference to the object we're interested in. If we didn't do that, we'd have to either duplicate all the code that uses e3 into both if and else, making sure to change the variable names after copy/pasting.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!