BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-23-2008, 04:58 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default global variable

Please Login to Remove!

Hi

How can i add a global variable in my project that I can call this variable since every class of the project. How can I do it?

thanks, Oscar
Offline  
Old 04-23-2008, 06:14 PM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use a public static variable, like so:

Code:
public class Foo {
   public static final int BAR = 23;
}
You could then use the following example line from anywhere in your app.

Code:
System.out.println("Foo.BAR = " + Foo.BAR);
__________________
Do your homework and know how to ask a good question.
Offline  
Old 04-24-2008, 07:54 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you very much!
Offline  
Old 04-27-2008, 06:12 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can not modify a public static final variable, How can I declare a public variable that I can modify?
Offline  
Old 04-27-2008, 12:32 PM   #5 (permalink)
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Read this. Be very careful about using Singletons as a simple substitute for global variables; they're absent from the language for a reason. It's your program though, I don't have to maintain it; so do what you want.
__________________
Do your homework and know how to ask a good question.
Offline  
Old 04-28-2008, 12:12 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The double check locking pattern fails for the RIM VM since the write orders are not guaranteed so if you use singletons the best thing you can do is make sure you instantiate them immediately in series before launching any additional threads.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.