Two Static HashTables

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 8
Reputation: vivek_green is an unknown quantity at this point 
Solved Threads: 0
vivek_green vivek_green is offline Offline
Newbie Poster

Two Static HashTables

 
0
  #1
Oct 23rd, 2007
HI,
Can someone tell me if two static hashtables declared with the same name in two different classes will cause ambiguity while acessing in each other classes without refering them with class Name.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 200
Reputation: nschessnerd is an unknown quantity at this point 
Solved Threads: 8
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Posting Whiz in Training

Re: Two Static HashTables

 
0
  #2
Oct 23rd, 2007
how would you access them without class names? can you give me an example?
this.love(*);
&hea/rts;
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 8
Reputation: vivek_green is an unknown quantity at this point 
Solved Threads: 0
vivek_green vivek_green is offline Offline
Newbie Poster

Re: Two Static HashTables

 
0
  #3
Oct 23rd, 2007
Hi,

Please find the example,
Consider two classes in the same package,

package p1;

class A
{
static Hashtable ins1 = new Hashtable();
void somemethod()
{
ins1.put("1","1");
}
}

package p1;
class B
{
static Hashtable ins1 = new Hashtable();
void somemethod()
{
ins1.put("1","1");
}
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 200
Reputation: nschessnerd is an unknown quantity at this point 
Solved Threads: 8
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Posting Whiz in Training

Re: Two Static HashTables

 
0
  #4
Oct 23rd, 2007
no it wouldnt matter, it only matters if you define the same variable twice inside of a method.
this.love(*);
&hea/rts;
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,505
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Two Static HashTables

 
0
  #5
Oct 23rd, 2007
Edit: This probably doesn't apply now based upon the example code you posted while I was responding. You mentioned using those two hashtables in other classes without qualifying them by name, which is not what your example indicates.

Of course it will cause ambiguity. The only way to use them without the class name would be to use static imports and if both variables have the same name they cannot be resolved.

Even if you could, why on earth would you?

Also note, unless you have specific reasons for needing Hashtable (if don't know what those reasons are then you don't need it), you should consider using HashMap instead.
Last edited by Ezzaral; Oct 23rd, 2007 at 1:09 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Two Static HashTables

 
0
  #6
Oct 23rd, 2007
and why use public static fields at all?
They're THE worst thing to use in Object Oriented programming, a clear sign that the programmer didn't know the first thing about what she was doing.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 8
Reputation: vivek_green is an unknown quantity at this point 
Solved Threads: 0
vivek_green vivek_green is offline Offline
Newbie Poster

Re: Two Static HashTables

 
0
  #7
Oct 23rd, 2007
hi,
I have just give u the sample only and not the real circumstance where i used it.It does sounds good where i used it.

Thanks,
Vivek
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,505
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Two Static HashTables

 
0
  #8
Oct 23rd, 2007
Originally Posted by vivek_green View Post
hi,
I have just give u the sample only and not the real circumstance where i used it.It does sounds good where i used it.

Thanks,
Vivek
As jwenting said, public statics for anything but constants is usually a poor idea. There is probably a much better way for you to make that data available to your other classes.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Two Static HashTables

 
0
  #9
Oct 24th, 2007
Last company I worked we had a banner on the wall reading "the only good global is an eliminated global".
That's how bad public static variables (and to a somewhat lesser degree methods) are.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC