Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Hiding Static Variables  (Read 1057 times)
0 Members and 1 Guest are viewing this topic.
Offline bh94704

Senior Newbie


« Posted 2004-07-19 20:05:19 »

I've got several classes of game object that are all descended from one basic class. I want each class to maintain its own static Hashtable, which will contain
every initialized instance of that class.

To this end, I declare a private static Hashtable objectTable in each class, and init them, in each class, in a static block.

Trouble is, all my classes always end up accessing the table for that basic class whenever I try to iaccess the table directly (ie - objectTable.put(...) or something). I've developed a very ugly workaround, wherein I place the exact same method:

Hashtable getObjectTable() {return objectTable;}

in every subclass, and always use getObjectTable().put(...) instead of just objectTable.put(...). Now the correct static table is always used. Why is this necessary? Am I doing something wrong or is this just how static hiding works? Thanks all,

Offline bh94704

Senior Newbie


« Reply #1 - Posted 2004-07-19 20:06:25 »

1.4.2, Windows XP BTW  Embarrassed
Offline swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

« Reply #2 - Posted 2004-07-20 03:24:44 »

Since it should not be possible to access private members of a base class from a derived class, I would have to say this is a bug.

You should file a bug report.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline bh94704

Senior Newbie


« Reply #3 - Posted 2004-07-20 18:54:30 »

Augh, yes, I must have changed it from protected at some point and forgotten that's how it originally was.

Thanks for the reply... I found this on the Sun Forums in case anyone else has this problem. The short answer is, yes, that's how it works. I can't think of why it should work that way, but what the hey.
Offline swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

« Reply #4 - Posted 2004-07-20 22:41:59 »

Ah, I think I may have misunderstood your original problem.

If it was base-class methods that were accessing the hashtable then it makes sense.

The two ways to solve the problem are the way you did it with an accessor method to get the hashtable, or to use 'put'/'get' methods in the derived classes that then access the hashtable methods directly, so the code reads a little nicer.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (11 views)
2015-07-29 04:35:27

Riven (33 views)
2015-07-27 16:38:00

Riven (16 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (28 views)
2015-07-25 00:14:37

BurntPizza (39 views)
2015-07-24 22:06:39

BurntPizza (22 views)
2015-07-24 06:06:53

NoxInc (26 views)
2015-07-22 22:16:53

NoxInc (17 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!