Results 1 to 5 of 5
Thread: Converting String to Usable code
- 09-21-2010, 07:18 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 31
- Rep Power
- 0
Converting String to Usable code
How would I make a method or a line of code from a string value? Say I typed in "i=1;" in a text field, is there a way to put that text in the compiling code? This is not about assigning values to variables, this is about being able to write a method in a running java program and then implement it. That would be awesome. Thanks in advance.
- 09-21-2010, 07:20 PM #2
While I'm not 100% sure, I'm fairly certain this cannot be done.
However, I must ask: Why do you wish to do this? A user could type an erroneous line of code and crash the application, or a malicious piece of code that manipulates the program in an undesirable way.
PS: You could parse it as JavaScript if you wanted... http://download.oracle.com/javase/6/...ide/index.html
- 09-21-2010, 07:35 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
... also you can have a look at BeanShell (google is your friend here).
kind regards,
Jos
- 09-21-2010, 08:50 PM #4
Or the JavaCompiler class would allow you to create a java source program, compile it and execute it within a java program.
-
I think that Groovy can do this innately, but I have never tried this.
Similar Threads
-
Converting string to byte[]
By bobo67 in forum New To JavaReplies: 12Last Post: 09-10-2010, 09:10 PM -
Converting to String
By darek9576 in forum New To JavaReplies: 1Last Post: 03-13-2010, 10:07 PM -
Is it OK to do this... (converting int to string)
By Psyclone in forum New To JavaReplies: 1Last Post: 02-16-2010, 05:51 PM -
Re-usable, dynamic pattern for error code-message mapping
By Algatron in forum Advanced JavaReplies: 3Last Post: 03-19-2009, 04:01 AM -
Converting object to string
By Preethi in forum New To JavaReplies: 4Last Post: 06-14-2008, 03:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks