R
Richard Chrenko
Which is the more risk free approach?
Let's say there's a method that does what gets the name directly from
the environment, like I want, we'll call it getVariableName();
Thingie fred = new Thingie( "fred" );
Thingie larry = new Thingie( "larry" );
fred = larry
println( fred.getName( ) );
println( getVariableName( fred ) );
So, in theory, which would most reliably return the information I wanted?
I considered the approach you suggested, I was just trying to find out
if there was a more dependable way to do it.
Ed.
It clearly depends upon what information you want. If you are designing a
debugger, the actual name of the Thingie instance may be helpful. If on
the other hand you are developing object-oriented applications (like the
vast majority of us on this newsgroup), your requirement is quite
puzzling. If you assign larry to fred, you are explicitly saying that you
want the object references larry and fred to access the same object (i.e.
contain the same information). So why differentiate between the two?
Are you by any chance coming to Java from the PHP world? I ask because PHP
permits data manipulations of the type you propose (as well as many other
oddities such as mathematical calculations with string variables!).