• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassCastException: java.util.Hashtable

 
Hariom Tiwari
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
else{
return true;
}
}

}
I have set values as follow:
Hashtable<String,Boolean> operations= new Hashtable<String, Boolean>();
operations.put("Review_DeleteQuote", true);
remoteEvents.setOperations(operations);
when I am trying to read it like
CustomerProducts.setOperations(remoteEvents.getOperations());
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
Sheriff
Pie
Posts: 48935
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic