java - How can I define a variable within an object with another variable -


the title might little confusing want know how can change ' b ' part in mainsave.b define within object.

here code far

public void getitem(int a, string b) {     mainsave.b = a; } 

the values being sent piece of code in class called story. want them stored in object of class savefile 'mainsave' is

if (command_string.equals("1"))         {            try {thread.sleep(1500);} catch (interruptedexception e) {}             system.out.println("you search shed thouroughly , find axe not else...");            int item = 1;            string axe = "axe";            getitem(item,axe);            try {thread.sleep(1500);} catch (interruptedexception e) {}               area1();         } 

the error when trying compile first part "cannot find symbol - variable b"

simply cannot since java statically typed language. variables names must realize @ compile time.

i don't suggest possible reflection coding.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -