Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about accessing static fields

 
Sarin Kuraganti
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sarin Kuraganti
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic