If you only have 4 different Strings
passed in, it'll be easier to do a switch than hack around with reflection. Another option especially with more than 4 different values is to create a Map<String, YourInterface>
so you can get the object with this.stuff = map.get(x);
. This requires that your objects are stateless.
switch(x) {
case "Foo":
this.stuff = new Foo();
break;
case "Bar":
this.stuff = new Bar();
break;
// etc.
}
Or in a more elegant way if you can just use the same reference:
Map<String, IAttack> attackMap = new HashMap<>(); // Assuming IAttack is an interface implemented by your classes
public MyClass() {
attackMap.put("Foo", new Foo());
attackMap.put("Bar", new Bar());
}
public void create(String x) {
this.stuff = attackMap.get(x);
}