I would like to call an object through the use of a generated string.
As you can see, name
is being generated correctly.
Also, the method for getting the object works fine.
However I can not use name to reference the object even though that is the name of the object.
Why is that? How can I solve this?
public class FrameTest{
public static void main(String[] args) {
ObjectMethod first_object = new ObjectMethod(); //instanciate object
first_object.setCost(2.5);
String object = "first";
String one = "object";
String name = object + "_" + one;
System.out.println(name);
System.out.println(first_object.getCost());
System.out.println(name.getCost()); //this line does not work
}
}
public class ObjectMethod{
public double value;
public void setCost(double cost) {
value = cost;
}
public double getCost() {
return value;
}
}