This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Common data for one (multi-instatianted) class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Common data for one (multi-instatianted) class" Watch "Common data for one (multi-instatianted) class" New topic

Common data for one (multi-instatianted) class

Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
I have the following class:

The object is to have this embedded class of flags and their descriptions to be common and immutable for all instantiantions of the user class.

I get an error that says:

/home/anw/SoftwareProducts/WebWork/infoisland/src/infoIsland/ non-static variable this cannot be referenced from a static context
new UserFlag(0x00000001, "smsntfy", "Notify me of private messages with an SMS message"),

when I try to do this.

I think it doesn't like the "new" keyword. Having said that, I've tried several combinations and permutations of syntax to try to achieve this (no "new" keyword, no "UserFlags" (so it's like an array initialization), etc.).

The goal is to have the same stuff for each user, and, for reasons of efficiency, I'd like to not to have separate instances of this for each user. What is the Java way to do this?


-------<br />Thanks & regards,<br />anw
Dave Lorde

Joined: Apr 02, 2007
Posts: 20
The inner class UserFlag is declared as an instance class, so you can't instantiate it at class (static) scope.

If you want to instantiate it at static scope, you must declare it a static member class:

Never hesitate to ask a lesser person...
Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
That did it!! Thanks!
I agree. Here's the link:
subject: Common data for one (multi-instatianted) class
It's not a secret anymore!