0

I'm writing a method which assigns a value to a variable with a given name, and should work something like this.

public void assignVariable(String varName, T val) {
        T varName = val;
}

Is there any way to implement something like this?

Simon
  • 139
  • 1
  • 5
  • Your design is wrong... what if the string passed in is `System.out` or `java`? Just override them? – user202729 May 19 '18 at 09:14
  • I don't see what you mean. Do you want to assign to a local variable? That's done. To a global? Declare it outside your method. Or as a class member. – z32a7ul May 19 '18 at 09:14
  • 1
    You probably want your class to hold a `Map` that maps name to variable. Make a `Map` – flakes May 19 '18 at 10:10

0 Answers0