• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execute a string

 
Lio Liov
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have trubles solving this problem
is there a way to execute together
Thanks



 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lio Liov wrote:I have trubles solving this problem

and the problem?
 
Lio Liov
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know how to execute the string word.toUpper();
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh,
 
Lio Liov
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks maybe I dont explain right
toUpper is going to be a String in my program(I am taking string from hash table)
So If I have the strings "word" and "toUpper()"
How can I convert word into upper cases
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to use reflection to do that.
 
dennis deems
Ranch Hand
Posts: 808
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection, like prayer, is the last resort of a scoundrel. You need the Strategy pattern. Create strategies for every String method you will need to call. Select a strategy based on the string you pull out of your map (this looks like a job for an enum), give the String to be worked on to the strategy, and set the strategy to work. Bam!
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Deems wrote:Reflection, like prayer, is the last resort of a scoundrel.

I've been called worse
 
Lio Liov
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the answer
Can you give me a few more hins
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lio Liov wrote:Thank you for the answer
Can you give me a few more hins

About what in particular ? Dennis gave you a link. If there's something there you still don't understand, then ask a specific question.
 
Tim Moores
Bartender
Posts: 2675
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are various libraries that can help with this kind of problem (executing Java code you have in string form); my favorite is Javassist.
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i have done is to use a HashMap(String, Class with that name)
 
Campbell Ritchie
Sheriff
Posts: 48374
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:[ . . . I've been called worse
Not by me, then.
 
Campbell Ritchie
Sheriff
Posts: 48374
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult for “beginning”. Moving discussion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic