Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
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 850 times)
0 Members and 1 Guest are viewing this topic.
Offline bh94704

Senior Newbie




AxAy(x=y)


« 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,

Bret
Offline bh94704

Senior Newbie




AxAy(x=y)


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

1.4.2, Windows XP BTW  Embarrassed
Offline swpalmer

JGO Coder




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




AxAy(x=y)


« 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.

http://forum.java.sun.com/thread.jsp?forum=31&thread=484011
Offline swpalmer

JGO Coder




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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (12 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (27 views)
2014-08-22 19:31:30

atombrot (40 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (34 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!