• Post Reply Bookmark Topic Watch Topic
  • New Topic

LinkedHashmap  RSS feed

 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am synchronizing an instance of LinkedHashMap using,
java.util.Map mapdet = Collections.synchronizedMap(new LinkedHashMap(50,(float)0.9));
Now I want to a mapdet.clone().
But I get a compiliation error saying,
"clone() has protected access in java.lang.Object"
What is the solution for this?
If I cast it to LinkedHashMap and then do clone(),it compiles properly.
But I have read somewhere that once u have applied the Collections.synchronizedMap to a actual Map obejct then u can use it
using api's defined in Map Object only.
Will this(cloning after typecasting) lead to any problems as far as
synchronized access to my object is concerned?
Thanks
Chinmay.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you will be OK, you are just synchronizing on mapdet rather than some other wrapper object. So, you'll do something like:
synchronized(mapdet) {
Object o = mapdet.clone();
...
}
[ August 23, 2003: Message edited by: Roger Chung-Wee ]
 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,
I did something like this,
"((LinkedHashMap)mapObj).clone();"
This compiled fine,but threw an exception during runtime.
I dont think I can do a clone() on an Object once it being referred to by its Interface.
Thanks again,
Chinmay
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!