• Post Reply Bookmark Topic Watch Topic
  • New Topic

About access to relevant variables from variable name  RSS feed

 
Jerome Gao
Greenhorn
Posts: 13
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,Now, I want to get this variable name according to the variable,

Otherwise, can to do write

Do not know with what method can be finished,Because it is in the method inside,So can't use reflection to complete his,
Thanks
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beginning Java question. Moving...
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not at all sure I understand the question. I would prefer to use loops, myself. You can of course get the String values from the loops, too.I presume that Map is a field, so it will remain in scope.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, you can't. If you want to be able to map strings to objects then a better approach is to use a Map from String to whatever type of object you want. It's a little difficult to demonstrate that in this example, because it's not clear what the point is.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might even consider using an array, instead of five named variables. But like Matthew suggests, it's pretty hard to say what you should do when the code in question is meaningless.
 
Jerome Gao
Greenhorn
Posts: 13
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Beginning Java question. Moving...

thank you,I've been thinking about which one should be in the area,But still wrong,Thank you for correcting me!



 
Jerome Gao
Greenhorn
Posts: 13
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I am not at all sure I understand the question. I would prefer to use loops, myself. You can of course get the String values from the loops, too.I presume that Map is a field, so it will remain in scope.

Hello,Campbell
Maybe I express way let you misunderstood, i flet very sorry !
I think you write only for content of the same code format,
If is the

,Then use this method is not very good,but you gave me the enlightenment,


use a 2d array,through the subscript obtain values !
Thank you,but my friend said a 2d array impact performance,Dont't know what you think about that ?

 
Jerome Gao
Greenhorn
Posts: 13
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:You might even consider using an array, instead of five named variables. But like Matthew suggests, it's pretty hard to say what you should do when the code in question is meaningless.

Hello, Paul,
I think is the ellipsis added code,It's like this


Only add once,yes ,i used the array !
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerome Gao wrote: . . .


use a 2d array,through the subscript obtain values !
There is no such thing as a 2D array. Only an array of arrays.

I still don’t understand why you insist on doing something by hand which the computer will do for you automatically.

Thank you,but my friend said a 2d array impact performance,Don't know what you think about that ?
Your friend is mistaken. Array access is very very fast.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!