简体   繁体   中英

how to create a global variable in a Eclipse PDT application?

I have an Eclipse PDT applicaction and I want/need to use a global variable that can be retrieved everywhere in the app.

I need a sort of "last_client" o "last invice" to let the application be more "agile" when the user goes from one screen to another. It's difficult to explain without an example, but basically I need a global variable so when teh application creates a combo for letting the user select an entities , the combo will be default to that global variable if is set.

Best Regards

Just refer to that class.that variable. Assuming the class is called "invoice" and the variable is called "user" it would look like:

lastUser = invoice.user;

You'd need to make the variable public to access it from a different class. If you want it to be private (and you should!) You'll need to create a getter method for it. Like:

public String returnUser()
{
return user;
}

And you'd call it from the other class like:

lastUser = invoice.returnUser;

Hope that's useful!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM