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

Traceable Thermocouple Thermometer, 2 Input, Type K 4137
$238.42
Traceable Thermocouple Thermometer, 2 Input, Type K 4137 pictureDigital PID DC SSR Thermostat Temperature Controller PT100 Thermocouple SensorW,
$1.92
Digital PID DC SSR Thermostat Temperature Controller PT100 Thermocouple SensorW, picture1m High Temperature -0~150 Degree Thermocouple K type 100mm Probe Dia Sensors
$3.29
1m High Temperature -0~150 Degree Thermocouple K type 100mm Probe Dia Sensors pictureK-type, Clip on Wet bulb Thermocouple Model: ATWB1
$20.99
K-type, Clip on Wet bulb Thermocouple Model: ATWB1 pictureCooperAtkiins 3520O-K Thermocouple Thermometer 1 input type k with instruction
$200.0
CooperAtkiins 3520O-K Thermocouple Thermometer 1 input  type k with instruction  picture






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