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

OEM Dell Dimension E310 E3100 Motherboard Intel P4 2.8GHz 1G Ram
$21.78
OEM Dell Dimension E310 E3100 Motherboard Intel P4 2.8GHz 1G Ram pictureDell CW796 Cover Top 1720 OEM Genuine NIB OEM
$39.95
Dell CW796 Cover Top 1720 OEM Genuine NIB OEM  pictureDELL 725-10263 / 331-1310 / KT74N Lamp manufactured by DELL
$195.86
DELL 725-10263 / 331-1310 / KT74N Lamp manufactured by DELL pictureOEM Dell 0PH344 375W PSU N375P-00 NPS-375AB A Power Supply for Precision 380 390
$22.98
OEM Dell 0PH344 375W PSU N375P-00 NPS-375AB A Power Supply for Precision 380 390 pictureNew Dell Genuine OEM Cyan Toner Cartridge H625 H825 S2825 P3HJK
$75.98
New Dell Genuine OEM Cyan Toner Cartridge H625 H825 S2825 P3HJK  picture






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