If I have a socket variable named ‘sock’ and lets say down the line for some reason you have to create a new socket, lets say its called ‘sock2’, and you set ‘sock2’ to equal ‘sock’. And then you throw away the variable ‘sock’. Will the connection still work, will ‘sock2’ still be able to communicate with the other end of the socket that was originally in ‘sock’?
Share
Since there is still a reference to the object that was originally
sock(in the form ofsock2), the Java garbage collection will not dispose of it, and you can still usesock2as if it weresock.