-5

I'm trying to convert a string in code in Java, but i have no idea how to do it or if it is possible.

This is my Java code (Measure is an other class I have created)

String str= "Measure m = new Measure(10,1);";

Is it possible to run the code in the string?

Giuseppe Romeo
  • 111
  • 1
  • 2
  • 13

1 Answers1

0

No I dont think that is a good practice, you don't need to do it that way, just instantiate outside of the string, it will be fine and good practice. Measure m = new Measure(10,1);

konz laugoko
  • 79
  • 1
  • 9
  • 1
    And what if the String is variable or even user dependent? There are lots of cases in which you need to execute code that is passed as a String. And there *are* ways to do that (see comments under the question). –  Jan 28 '18 at 09:05