Re: Public Static Final



On 31 Mar 2007 12:57:55 -0700, Sandy wrote:

I have a series of values which I want to use as constants. I want
them to be constants useable throughout my application, not just a
single class.

I thought that if I declared them 'Public Static Final int X = 1' then
from all classes I could access X.

Ie: in class Barney I use:
Public Static Final int STRENGTH = 1;

then in class Fred I could say:

if(type == STRENGTH)
{
// do stuff
}

In my case I get the error: cannot find symbol variable STRENGTH.

I am obviously doing it incorrectly.

How SHOULD I declare my public constants that I want to use
application wide?

Thanks.

Use the class name before the constant name when you reference it from
another class:

if (type == Barney.STRENGTH)
{
etc.

(And I am sure you had lower case letters starting public static and
final.)

.



Relevant Pages

  • Re: Public Static Final
    ... Sandy wrote: them to be constants useable throughout my application, ... single class. ... I thought that if I declared them 'Public Static Final int X = 1' then ... Public Static Final int STRENGTH = 1; ...
    (comp.lang.java.help)
  • Public Static Final
    ... single class. ... Public Static Final int STRENGTH = 1; ... How SHOULD I declare my public constants that I want to use ...
    (comp.lang.java.help)
  • Re: Really tough ADO Stored Procedure Question. Please Help!!!
    ... @lScenarioID_CopyFrom int, ... DECLARE @ErrMSG varchar--This is the max msg size ... ROLLBACK TRANSACTION ... SELECT @lRowCountHolder = MIN ...
    (microsoft.public.sqlserver.odbc)
  • Re: Really tough ADO Stored Procedure Question. Please Help!!!
    ... @lScenarioID_CopyFrom int, ... DECLARE @ErrMSG varchar--This is the max msg size ... ROLLBACK TRANSACTION ... SELECT @lRowCountHolder = MIN ...
    (microsoft.public.sqlserver.programming)
  • Re: Really tough ADO Stored Procedure Question. Please Help!!!
    ... @lScenarioID_CopyFrom int, ... DECLARE @ErrMSG varchar--This is the max msg size ... ROLLBACK TRANSACTION ... SELECT @lRowCountHolder = MIN ...
    (microsoft.public.sqlserver.server)