aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes about accessing static fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "about accessing static fields" Watch "about accessing static fields" New topic
Author

about accessing static fields

Sarin Kuraganti
Greenhorn

Joined: Sep 04, 2003
Posts: 24
Hi all,
I am getting the following error in Eclipse 2.1:
Error"case expressions must be constant expressions"
Actually this is about accessing the static fields. Currently the .java classes access the static fields using an instance of that java class as shown below:
AUIRegistrationStateImpl RegState = (AUIRegistrationStateImpl)session.getValue(m_StateName);
switch(RegState.getCurrentState())
{
case RegState.STATE_ID_SEARCH:
iPageID = PageID.PAGE_ID_AUI_REGISTRATION_SEARCH;
break;
case RegState.STATE_ID_SEARCH_RESULTS:
iPageID = PageID.PAGE_ID_AUI_REGISTRATION_SEARCH_RESULT;
break;
...
}
I understand that the better way of accessing static fields is using the class name, for example: AUIRegistrationStateImpl.STATE_ID_SEARCH in my switch - case structure. But, what I feel is Eclipse should not bother about this. Even after setting the compiler settings to ignore such usage in switch-case, Eclipse still shows these as errors in my Task window and I am unable to build the whole project without errors. Is this only with Eclipse 2.1 or can I get rid of these errors? The static fields have been defined as "public static final int". Please note that the java classes I have are "Read Only".
Awaiting some response from you wonderful people out there.
regards,
Sarin
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by sarin kuraganti:
I understand that the better way of accessing static fields is using the class name, for example: AUIRegistrationStateImpl.STATE_ID_SEARCH in my switch - case structure.

Have you tried that? That is, are you sure that all your fields are really "final static"?

But, what I feel is Eclipse should not bother about this.

Yes. If it does, it's a bug in the eclipse compiler, as far as I can tell.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Sarin Kuraganti
Greenhorn

Joined: Sep 04, 2003
Posts: 24
Hi Preuss,
Yes, I checked that, i.e all the fields are "public final static int". The strange thing that I noticed is that Eclipse flips between showing the static usage of such variables as "Warnings" sometimes and as "Errors" sometimes.
I have read in some other forum that this problem doesn't come up if we use Eclipse 2.0.1, but it does with Eclipse 2.1. I am not sure how far this is true 'coz I haven't used Eclipse 2.0.1.
regards,
Sarin
 
 
subject: about accessing static fields