BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-23-2008, 03: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, 05: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, 06: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, 05: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, 11:32 AM   #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-27-2008, 11:12 PM   #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

IBM OEM DPES-31080 DPES31080 Drive Disk 1080MB
$229.0
IBM OEM DPES-31080 DPES31080 Drive Disk 1080MB pictureIBM Lenovo THINKPAD LAPTOP AC POWER ADAPTER 20V 3.2.5A OEM 92P1156 42T5282
$11.0
IBM Lenovo THINKPAD LAPTOP AC POWER ADAPTER 20V 3.2.5A OEM 92P1156 42T5282 pictureIBM #4 Y Cable Genuine OEM Long POS Cash Register 4A to 4B 10N1002 J96367
$24.99
IBM #4 Y Cable Genuine OEM Long POS Cash Register 4A to 4B 10N1002 J96367 pictureIBM 1136433 OEM Ribbon,
$25.68
IBM 1136433 OEM Ribbon, pictureLOT of 13 GENUINE OEM IBM EASYSTRIKE LIFT OFF TAPE CASSETTES #1337765
$45.0
LOT of 13 GENUINE OEM IBM EASYSTRIKE LIFT OFF TAPE CASSETTES #1337765  picture






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