This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ClassCastException: java.util.Hashtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ClassCastException: java.util.Hashtable" Watch "ClassCastException: java.util.Hashtable" New topic

ClassCastException: java.util.Hashtable

Hariom Tiwari

Joined: Jun 15, 2008
Posts: 10
Hi all,
I have to return true or false from a Map. I have extended the HastTable class for this.
Please see the below code snippet.
public class MapUtil<S,B> extends Hashtable<String, Boolean> {
public boolean get(String key){
Boolean isAvailable=(Boolean)super.get(key);
if(isAvailable!= null)
return isAvailable.booleanValue();
return true;

I have set values as follow:
Hashtable<String,Boolean> operations= new Hashtable<String, Boolean>();
operations.put("Review_DeleteQuote", true);
when I am trying to read it like
it is throwing java.lang.ClassCastException: java.util.Hashtable exception

I have written setOperations() as below
public static void setOperations(Hashtable<String, Boolean> operations) {
CustomerProducts.operations = (MapUtil<String, Boolean> operations;

please let me know where I am doing mistake.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45307
Please edit your post to use code tags, and also click the "Disable smilies in this post." box; both will make your post easier to read.

Read what object you are passing and what you are casting it to. I hope that will explain your problem. Why are you creating the MapUtil class and not using it as a parameter?
I agree. Here's the link:
subject: ClassCastException: java.util.Hashtable
jQuery in Action, 3rd edition